﻿Imports System
Imports System.IO

Public Class ProjectService

    'Private Shared _projectConfigFile As String

    Shared Sub New()

    End Sub

    'revised
    Public Shared Sub CreateBasicInfo(ByVal pi As ProjectItem)
        Dim strSql As String
        Dim tic As New TBCC.Utility.TranstrationItem
        '20100423增加工程类型字段
        strSql = "Insert Into tbccProject(ProjectID,ProjectName,listNo,remark,phoneNumber,ConnectType," _
                & "ComNumber,imageCount,AuthCode,VersionNo,ProjectType,IPAddress,IPPort,phonePort) Values(?p0,?p1,?p2,?p3,?p4,?p5,?p6,?p7,?p8,?p9,?p10,?p11,?p12,?p13)"

        Dim p(13) As MySql.Data.MySqlClient.MySqlParameter
        For i As Integer = 0 To p.GetUpperBound(0)
            p(i) = New MySql.Data.MySqlClient.MySqlParameter
            p(i).ParameterName = "p" + i.ToString
        Next

        p(0).Value = pi.ProjectID
        p(1).Value = pi.ProjectName
        p(2).Value = pi.listNo
        p(3).Value = pi.Remark
        p(4).Value = pi.Phone
        p(5).Value = pi.connectType
        p(6).Value = pi.ComNumber
        p(7).Value = pi.imageList.Count
        p(8).Value = pi.AuthCode
        p(9).Value = pi.VersionNo
        p(10).Value = pi.ProjectType
        p(11).Value = pi.IPAddress
        p(12).Value = pi.IPPort
        p(13).Value = pi.PhonePort

        tic.Add(strSql, p)

        '增加该工程的数据字典记录
        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "CarWebServiceAdd", "")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "WebServiceDataUpload", IIf(g_WebServiceDataUpload, 1, 0))
        'tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "AlarmSoundFile", "")
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "DisableAlarmSound", "1")
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "UniformityPath", "")
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "UniformityTime", "")
        tic.Add(strSql, Nothing)

        '文档查询类型:1:秒,2:分钟;3:小时
        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "DocViewType", "3")
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "DocViewValue", "1")
        tic.Add(strSql, Nothing)

        'Tcp/ip心跳超时参数设置
        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "ClientSocket_Heartbeat_IdleTime", "25")
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "ClientSocket_Heartbeat_WaitTime", "5")
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "ClientSocket_Heartbeat_Rep", "3")
        tic.Add(strSql, Nothing)
        '**************************************************************
        '2009年06月10日 李吉鹏增加
        '**************************************************************
        '是否允许直连方式后台上传数据: 0:False,1:True
        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "BackgroundUploadHistoryData_Com", IIf(g_BackgroundUploadHistoryData_Com, 1, 0))
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "g_BackgroundUploadDiData_Com", IIf(g_BackgroundUploadDiData_Com, 1, 0))
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "BackgroundUploadAlarm_Com", IIf(g_BackgroundUploadAlarm_Com, 1, 0))
        tic.Add(strSql, Nothing)


        '是否允许拨号后台上传数据: 0:False,1:True
        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "BackgroundUploadHistoryData_Tel", IIf(g_BackgroundUploadHistoryData_Tel, 1, 0))
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "g_BackgroundUploadDiData_Tel", IIf(g_BackgroundUploadDiData_Tel, 1, 0))
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "BackgroundUploadAlarm_Tel", IIf(g_BackgroundUploadAlarm_Tel, 1, 0))
        tic.Add(strSql, Nothing)
        '是否允许TCP后台上传数据: 0:False,1:True
        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "BackgroundUploadHistoryData_Tcp", IIf(g_BackgroundUploadHistoryData_Tcp, 1, 0))
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "BackgroundUploadAlarm_Tcp", IIf(g_BackgroundUploadAlarm_Tcp, 1, 0))
        tic.Add(strSql, Nothing)

        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "g_BackgroundUploadDiData_Tcp", IIf(g_BackgroundUploadDiData_Tcp, 1, 0))
        tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "g_BackgroundUploadDiData_Tcp", IIf(g_BackgroundUploadDiData_Tcp, 1, 0))
        'tic.Add(strSql, Nothing)


        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType1max", "7.7")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType1min", "2.3")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType2max", "20")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType2min", "2")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType3max", "-15")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType3min", "-28")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType4max", "-20")
        'tic.Add(strSql, Nothing)

        'strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "TemType4min", "-28")
        'tic.Add(strSql, Nothing)



        '**************************************************************

        '提供webservice参数修改状态值标志
        strSql = String.Format("Insert Into tbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, "ChangedDatetime", UtilityClass.GetDateString(DateTime.MinValue))
        tic.Add(strSql, Nothing)



        SqlHelper.ExecuteTranstration(tic)

    End Sub

    'revised
    Public Shared Sub UpdateBasicInfo(ByVal pi As ProjectItem)

        Dim strSql As String
        Dim p(11) As MySql.Data.MySqlClient.MySqlParameter
        Dim tic As New TBCC.Utility.TranstrationItem

        strSql = "Update tbccProject Set projectName=?p0,listNo=?p1,Remark=?p2,phoneNumber=?p3,ConnectType=?p4,ComNumber=?p5,ImageCount=?p6,AuthCode=?p7,IPAddress=?p9,IPPort=?p10,phonePort=?p11 Where ProjectID=?p8"


        For i As Integer = 0 To p.GetUpperBound(0)
            p(i) = New MySql.Data.MySqlClient.MySqlParameter
            p(i).ParameterName = "p" + i.ToString
        Next

        p(0).Value = pi.ProjectName
        p(1).Value = pi.listNo
        p(2).Value = pi.Remark
        p(3).Value = pi.Phone
        p(4).Value = pi.connectType
        p(5).Value = pi.ComNumber
        p(6).Value = pi.imageList.Count
        p(7).Value = pi.AuthCode
        p(8).Value = pi.ProjectID
        p(9).Value = pi.IPAddress
        p(10).Value = pi.IPPort
        p(11).Value = pi.PhonePort

        tic.Add(strSql, p)

        SqlHelper.ExecuteTranstration(tic)
    End Sub

    Public Shared Function UpdatePrjDataToDb(ByVal pi As ProjectItem, ByVal netcount As Integer, ByVal nettype As Integer) As Boolean
        Dim strSql As String
        Dim pid_str As String
        Dim iTemp As Integer = 0
        pid_str = Trim(pi.ProjectID).Replace("-", "_")
        Dim tic As New TBCC.Utility.TranstrationItem


        '删除已存在的工程的数据

        '删除工程信息总表中的数据
        strSql = String.Format("Delete From tbccProject Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程信息字典中的数据
        strSql = String.Format("Delete From tbccDictory Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程图表的数据
        strSql = String.Format("Delete From tbccProjectImages Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程图表中显示组件中的数据
        strSql = String.Format("Delete From tbccImageControls Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程类型数据
        strSql = String.Format("Delete From TbccDevType Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程冷库信息数据
        strSql = String.Format("Delete From TbccRefInfo Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程AI信息数据
        strSql = String.Format("Delete From TbccAiInfo Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程DI/DO信息数据
        strSql = String.Format("Delete From TbccDiDoInfo Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程设备自检数据
        strSql = String.Format("Delete From tbccCheckAlarm Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除参数校准数据
        strSql = String.Format("Delete From tbccCalibLog Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除历史报警文档数据数据
        strSql = String.Format("Delete From tbccHDAlarmDoc Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除IO离线配置端口
        strSql = String.Format("Delete From tbccIOInfo_Offline Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除IO离线配置端口
        strSql = String.Format("Delete From tbccIOInfo_Offlinecold Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除IO离线配置参数
        strSql = String.Format("Delete From tbccIOParameter_Offline Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除IO离线配置参数
        strSql = String.Format("Delete From tbccIOParameter_Offlinecold Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)




        '删除制冷设备参数
        strSql = String.Format("delete from TbccCcapDevType where projectID='{0}' ", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除启停数据表
        strSql = String.Format("delete from tbcchddatastartendpage where projectID='{0}' ", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除手动上传数据表
        strSql = String.Format("delete from tbcchdmanualuploadrecord where projectID='{0}' ", pi.ProjectID)
        tic.Add(strSql, Nothing)



        '删除当前工程某网络的历史数据表
        'For Each dti As DevTypeItem In pi.DevTypeGroupList
        For i As Integer = 1 To netcount
            strSql = String.Format("Drop TABLE if exists tbccHDData_{0}_{1}", pid_str, i)
            tic.Add(strSql, Nothing)
        Next

        For j As Integer = 100 To nettype
            strSql = String.Format("Drop TABLE if exists tbccHDData_{0}_{1}", pid_str, j)
            tic.Add(strSql, Nothing)
        Next

        If netcount > 0 OrElse nettype > 99 Then
            '删除当前工程某网络的历史索引数据表
            strSql = String.Format("Drop TABLE if exists tbccHistoryData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警数据表
            strSql = String.Format("Drop TABLE if exists tbccHDAlarmData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警索引数据表
            strSql = String.Format("Drop TABLE if exists tbccAlarmData_{0}", pid_str)
            tic.Add(strSql, Nothing)



            '20100915DI 历史数据显示
            '删除当前工程DI历史数据索引表
            strSql = String.Format("Drop TABLE if exists tbccHDDiData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程DI历史数据表
            strSql = String.Format("Drop TABLE if exists tbccDiData_{0}", pid_str)
            tic.Add(strSql, Nothing)

        End If

        '更新支持旧项目导入时，分离连接信息参数：IP地址与电话号码参数
        Select Case pi.connectType
            Case 0
                pi.PhonePort = pi.ComNumber
                pi.ComNumber = 0

                '增加工程信息到数据库tbccProject
                strSql = String.Format("Insert Into tbccProject(ProjectID,ProjectName,listNo,remark,phoneNumber,ConnectType," _
                & "ComNumber,imageCount,AuthCode,VersionNo,ProjectType,IPAddress,IPPort,phonePort) Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')", pi.ProjectID, pi.ProjectName, pi.listNo, pi.Remark, pi.Phone, pi.connectType, pi.ComNumber, pi.imageList.Count, pi.AuthCode, pi.VersionNo, pi.ProjectType, pi.IPAddress, pi.IPPort, pi.PhonePort)
                tic.Add(strSql, Nothing)
            Case 1

                '增加工程信息到数据库tbccProject
                strSql = String.Format("Insert Into tbccProject(ProjectID,ProjectName,listNo,remark,phoneNumber,ConnectType," _
                & "ComNumber,imageCount,AuthCode,VersionNo,ProjectType,IPAddress,IPPort,phonePort) Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')", pi.ProjectID, pi.ProjectName, pi.listNo, pi.Remark, pi.Phone, pi.connectType, pi.ComNumber, pi.imageList.Count, pi.AuthCode, pi.VersionNo, pi.ProjectType, pi.IPAddress, pi.IPPort, pi.PhonePort)
                tic.Add(strSql, Nothing)
            Case Else
                If pi.IPAddress = "" Then
                    pi.IPAddress = pi.Phone
                    pi.IPPort = 8000
                    pi.Phone = ""
                    pi.ComNumber = 0

                End If

                '增加工程信息到数据库tbccProject
                strSql = String.Format("Insert Into tbccProject(ProjectID,ProjectName,listNo,remark,phoneNumber,ConnectType," _
                & "ComNumber,imageCount,AuthCode,VersionNo,ProjectType,IPAddress,IPPort,phonePort) Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')", pi.ProjectID, pi.ProjectName, pi.listNo, pi.Remark, pi.Phone, pi.connectType, pi.ComNumber, pi.imageList.Count, pi.AuthCode, pi.VersionNo, pi.ProjectType, pi.IPAddress, pi.IPPort, pi.PhonePort)
                tic.Add(strSql, Nothing)

        End Select



        '工程字典数据TbccDictory
        For Each item As KeyValueItem In pi.DictoryItem.DicList
            item.value = item.value.Replace("\", "/")
            strSql = String.Format("Insert into TbccDictory(projectID,`key`,`value`) Values('{0}','{1}','{2}')", pi.ProjectID, item.key, item.value)
            tic.Add(strSql, Nothing)
        Next

        For Each pii As ProjectImageItem In pi.imageList
            '增加工程图表信息tbccProjectImages
            pii.imagePath = pii.imagePath.Replace("\", "/")

            strSql = String.Format("Insert Into tbccProjectImages(imageID,projectID,Imagename,listNo,imagePath) Values('{0}','{1}','{2}','{3}','{4}')", pii.ImageID, pi.ProjectID, pii.imageName, pii.ImageOrder, pii.imagePath)
            tic.Add(strSql, Nothing)

            For Each ici As ImgControlItem In pii.ImgControlItemGroupList
                '增加总工程图中显示组件数据tbccImageControls
                strSql = String.Format("Insert Into tbccImageControls(ProjectID,Netid,Refid,DataType,PortNo,ImageID,TitleMsg,TipMsg,UnitMsg," _
                & "cLeft,cTop,cWidth,cHeight) Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}')", pi.ProjectID, ici.Netid, ici.Refid, ici.DataType, ici.PortNo, ici.ImageID, ici.TitleMsg, ici.TipMsg, ici.UnitMsg, ici.cLeft, ici.cTop, ici.cWidth, ici.cHeight)
                strSql &= " -- " & iTemp
                iTemp += 1
                tic.Add(strSql, Nothing)
            Next
        Next

        For Each dti As DevTypeItem In pi.DevTypeGroupList
            '工程类型数据TbccDevType
            strSql = String.Format("Insert into TbccDevType(projectID,Netid,DevType,RefNum,devAppType) Values('{0}','{1}','{2}','{3}','{4}')", pi.ProjectID, dti.NetId, dti.DevType, dti.RefNum, dti.DevAppType)
            tic.Add(strSql, Nothing)
            '**************************************************************
            '20090616 李吉鹏增加 为增加温湿度基准线及控制显示功能在数据库中增加字段

            For Each rti As RefTypeItem In dti.RefTypeGroupList
                '冷库信息TbccRefInfo
                strSql = String.Format("Insert into TbccRefInfo(projectID,Netid,Refid,RealRefId,RefName," & _
                                        "HDCurveTempUp,HDCurveTempDown,HDCurveHumiUp,HDCurveHumiDown,HdCurveTempLineUp," & _
                                        "HdCurveTempLineDown,HDCurveHumiLineUp,HDCurveHumiLineDown," & _
                                        "HDCurveTempLineUpShow,HDCurveTempLineDownShow,HDCurveHumiLineUpShow,HDCurveHumiLineDownShow,FloorType,FloorNo,RefType)" & _
                                        " Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}')", _
                                         pi.ProjectID, rti.NetId, rti.RefId, rti.RealRefId, rti.RefName, rti.HDCurveTempUp, rti.HDCurveTempDown, rti.HDCurveHumiUp, rti.HDCurveHumiDown, _
                                         rti.HDCurveTempLineUp, rti.HDCurveTempLineDown, rti.HDCurveHumiLineUp, rti.HDCurveHumiLineDown, _
                                          IIf(rti.HDCurveTempLineUpShow, 1, 0), IIf(rti.HDCurveTempLineDownShow, 1, 0), IIf(rti.HDCurveHumiLineUpShow, 1, 0), IIf(rti.HDCurveHumiLineDownShow, 1, 0), rti.FloorType, rti.FloorNo, rti.RefType)
                tic.Add(strSql, Nothing)
                '**************************************************************************************


                'AI端口TbccAiInfo
                For Each apti As AiPortTypeItem In rti.AiPortTypeGroupList
                    strSql = String.Format("Insert Into TbccAiInfo(projectID,Netid,Refid,SeqPortNo,PortNo,PortName,DataType,CurveChecked,PortNoType) " & _
                             "Values('{0}',{1},{2},{3},{4},'{5}',{6},'{7}','{8}')", pi.ProjectID, apti.NetId, apti.RefId, apti.SeqPortNo, apti.PortNo, apti.PortName, apti.DataType, apti.CurveChecked, apti.PortNoType)
                    strSql &= " -- " & iTemp
                    iTemp += 1
                    tic.Add(strSql, Nothing)
                Next

                '20100915增加DO库门2端口
                'DI/DO端口激活信息TbccDiDoInfo
                strSql = String.Format("Insert Into TbccDiDoInfo(projectID,Netid,Refid,DoorStatusPort,LostPowerPort,SoundAlarmPort,RefAlarmPort,DoorStatusPort2,JointActionPort,JointActionOpen_Output_Nu,JointActionClose_Output_Nu,JointAction_Output_Nu,DefrostStatus_Input_Nu,GeneratorPreAlarm,Cooling_Input_Nu,CompressorSetFailure_Input_Nu,CompressorFailure_Input_Nu,DefrostTemp_Input_Nu,Compressor_Input_Nu) " & _
                    "Values('{0}',{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18})", pi.ProjectID, rti.DiDoPortInfo.NetId, rti.DiDoPortInfo.RefId, rti.DiDoPortInfo.DoorStatusPort, rti.DiDoPortInfo.LostPowerPort, rti.DiDoPortInfo.SoundAlarmPort, rti.DiDoPortInfo.RefAlarmPort, rti.DiDoPortInfo.DoorStatusPort2, _
                      rti.DiDoPortInfo.JointActionPort, rti.DiDoPortInfo.JointActionOpen_Output_Nu, rti.DiDoPortInfo.JointActionClose_Output_Nu, rti.DiDoPortInfo.JointAction_Output_Nu, rti.DiDoPortInfo.DefrostStatus_Input_Nu, rti.DiDoPortInfo.GeneratorPreAlarm_Nu, rti.DiDoPortInfo.Cooling_Input_Nu, rti.DiDoPortInfo.CompressorSetFailure_Input_Nu, rti.DiDoPortInfo.CompressorFailure_Input_Nu, rti.DiDoPortInfo.DefrostTemp_Input_Nu, rti.DiDoPortInfo.Compressor_Input_Nu)
                strSql &= " -- " & iTemp
                iTemp += 1
                tic.Add(strSql, Nothing)

                'IO端口离线配置tbccIOInfo_Offline
                For Each ipi As IOPortTypeItem In rti.IOPortTypeGroupList
                    If ipi.DataType = 0 AndAlso ipi.SeqPortNo >= 7 Then
                        strSql = String.Format("Insert Into tbccIOInfo_Offlinecold(projectID,Netid,Refid,SeqPortNo,PortType,PortNo,PortName,DataType) Values('{0}',{1},{2},{3},{4},{5},'{6}',{7}) ", pi.ProjectID, ipi.NetId, ipi.RefId, ipi.SeqPortNo, ipi.PortType, ipi.PortNo, ipi.PortName, ipi.DataType)
                        strSql &= " -- " & iTemp
                        iTemp += 1
                        tic.Add(strSql, Nothing)
                    Else
                        strSql = String.Format("Insert Into tbccIOInfo_Offline(projectID,Netid,Refid,SeqPortNo,PortType,PortNo,PortName,DataType,PortNoType) Values('{0}',{1},{2},{3},{4},{5},'{6}',{7},{8}) ", pi.ProjectID, ipi.NetId, ipi.RefId, ipi.SeqPortNo, ipi.PortType, ipi.PortNo, ipi.PortName, ipi.DataType, ipi.PortNoType)
                        strSql &= " -- " & iTemp
                        iTemp += 1
                        tic.Add(strSql, Nothing)
                    End If
                    
                Next

                '20100915增加库门2延时时间

                'IO参数离线配置tbccIOParameter_Offline(),带有预警参数
                strSql = String.Format("Insert Into tbccIOParameter_Offline(projectID,Netid,Refid," & _
                                                    "AlarmTempHigh,AlarmTempLow,AlarmHumiHigh,AlarmHumiLow," & _
                                                    "DoorAlarmDelay,DoorPreAlarmDelay,LostAlarmDelay,LostPreAlarmDelay," & _
                                                    "TempHighAlarmDelay,TempHighPreDelay,TempLowAlarmDelay,TempLowPreDelay," & _
                                                    "HumiHighAlarmDelay,HumiHighPreDelay,HumiLowAlarmDelay,HumiLowPreDelay,AlarmTempHighPer,AlarmTempLowPer,AlarmHumiHighPer,AlarmHumiLowPer,Door2PreAlarmDelay,Door2AlarmDelay,DoorCoalitionDelay,GeneratorPreAlarmDelayTime) " & _
                                                    "Values('{0}',{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26}) ", _
                                                    pi.ProjectID, rti.NetId, rti.RefId, _
                                                    rti.IOParameterItem.AlarmTempHigh, rti.IOParameterItem.AlarmTempLow, rti.IOParameterItem.AlarmHumiHigh, rti.IOParameterItem.AlarmHumiLow, _
                                                    rti.IOParameterItem.DoorAlarmDelay, rti.IOParameterItem.DoorPreAlarmDelay, rti.IOParameterItem.LostAlarmDelay, rti.IOParameterItem.LostPreAlarmDelay, _
                                                    rti.IOParameterItem.TempHighAlarmDelay, rti.IOParameterItem.TempHighPreDelay, rti.IOParameterItem.TempLowAlarmDelay, rti.IOParameterItem.TempLowPreDelay, _
                                                    rti.IOParameterItem.HumiHighAlarmDelay, rti.IOParameterItem.HumiHighPreDelay, rti.IOParameterItem.HumiLowAlarmDelay, rti.IOParameterItem.HumiLowPreDelay, rti.IOParameterItem.AlarmTempHighPer, rti.IOParameterItem.AlarmTempLowPer, rti.IOParameterItem.AlarmHumiHighPer, rti.IOParameterItem.AlarmHumiLowPer, rti.IOParameterItem.Door2PreAlarmDelay, rti.IOParameterItem.Door2AlarmDelay, rti.IOParameterItem.DoorCoalitionDelay, rti.IOParameterItem.GeneratorPreAlarmDelayTime)


                strSql &= " -- " & iTemp
                iTemp += 1
                tic.Add(strSql, Nothing)

                'IO参数离线配置tbccIOParameter_Offline(),带有预警参数
                strSql = String.Format("Insert Into tbccIOParameter_Offlinecold(projectID,Netid,Refid," & _
                                                    "JointActionOpen_CloseDwLimit,JointActionClose_CloseDwLimit,JointActionClose_CloseLimit,JointActionOpen_CloseUpLimit,CompressorSetFailurePreAlarm_DelayTime,CompressorFailurePreAlarm_DelayTime,DefrostPreAlarm_DelayTime) " & _
                                                    "Values('{0}',{1},{2},{3},{4},{5},{6},{7},{8},{9}) ", _
                                                    pi.ProjectID, rti.NetId, rti.RefId, _
                                                    rti.IOParameterItem.JointActionOpen_CloseDwLimit, rti.IOParameterItem.JointActionClose_CloseDwLimit, rti.IOParameterItem.JointActionClose_CloseLimit, rti.IOParameterItem.JointActionOpen_CloseUpLimit, rti.IOParameterItem.CompressorSetFailurePreAlarm_DelayTime, rti.IOParameterItem.CompressorFailurePreAlarm_DelayTime, rti.IOParameterItem.DefrostPreAlarm_DelayTime)

                strSql &= " -- " & iTemp
                iTemp += 1
                tic.Add(strSql, Nothing)

            Next


            If dti.DevAppType = 17 OrElse dti.DevAppType = 1 Then

                '创建当前工程某网络的历史数据表
                strSql = String.Format("Create TABLE tbccHDData_{0}_{1}(id bigint not null auto_increment,hDate datetime,Uploadtime datetime,AI1 float(5,2),AI2 float(5,2),AI3 float(5,2)" _
                   & ",AI4 float(5,2),AI5 float(5,2),AI6 float(5,2),AI7 float(5,2),AI8 float(5,2),AI9 float(5,2),AI10 float(5,2),AI11 float(5,2),AI12 float(5,2)" _
                   & ",Ref1_RefAlarmState TINYINT,Ref1_LostPowerState TINYINT,Ref1_SoundOutputState TINYINT,Ref1_DoorState TINYINT,Ref1_ActiveState TINYINT" _
                   & ",Ref2_RefAlarmState TINYINT,Ref2_LostPowerState TINYINT,Ref2_SoundOutputState TINYINT,Ref2_DoorState TINYINT,Ref2_ActiveState TINYINT" _
                   & ",Ref3_RefAlarmState TINYINT,Ref3_LostPowerState TINYINT,Ref3_SoundOutputState TINYINT,Ref3_DoorState TINYINT,Ref3_ActiveState TINYINT" _
                   & ",Ref4_RefAlarmState TINYINT,Ref4_LostPowerState TINYINT,Ref4_SoundOutputState TINYINT,Ref4_DoorState TINYINT,Ref4_ActiveState TINYINT,Ref5_DoorState TINYINT,Ref6_DoorState TINYINT,Ref7_DoorState TINYINT,Ref8_DoorState TINYINT" _
                   & ", Primary Key(id))", pid_str, dti.NetId)
                tic.Add(strSql, Nothing)

                '创建当前工程某网络的历史数据表的时间索引
                strSql = String.Format("CREATE INDEX index_hDate_{0}_{1} On tbccHDData_{2}_{3}(hDate)", pid_str, dti.NetId, pid_str, dti.NetId)
                tic.Add(strSql, Nothing)
            ElseIf dti.DevAppType = 18 OrElse dti.DevAppType = 16 Then

                '创建当前工程某网络的历史数据表
                strSql = String.Format("Create TABLE tbccHDData_{0}_{1}(id bigint not null auto_increment,hDate datetime,Uploadtime datetime,AI1 float(5,2),AI2 float(5,2),AI3 float(5,2)" _
                   & ",AI4 float(5,2),AI5 float(5,2),AI6 float(5,2),AI7 float(5,2),AI8 float(5,2),AI9 float(5,2),AI10 float(5,2),AI11 float(5,2),AI12 float(5,2),AI13 float(5,2),AI14 float(5,2),AI15 float(5,2),AI16 float(5,2)" _
                   & ",AI17 float(5,2),AI18 float(5,2),AI19 float(5,2),AI20 float(5,2),AI21 float(5,2),AI22 float(5,2),AI23 float(5,2),AI24 float(5,2),AI25 float(5,2),AI26 float(5,2),AI27 float(5,2)" _
                   & ",AI28 float(5,2),AI29 float(5,2),AI30 float(5,2),AI31 float(5,2),AI32 float(5,2)" _
                   & ",Ref1_LostPowerState TINYINT,Ref1_SoundOutputState TINYINT,Ref1_RefAlarmState TINYINT,Ref1_ActiveState TINYINT,Ref2_RefAlarmState TINYINT,Ref2_ActiveState TINYINT" _
                   & ",Ref3_RefAlarmState TINYINT,Ref3_ActiveState TINYINT,Ref4_RefAlarmState TINYINT,Ref4_ActiveState TINYINT,Ref5_RefAlarmState TINYINT,Ref5_ActiveState TINYINT,Ref6_RefAlarmState TINYINT,Ref6_ActiveState TINYINT" _
                   & ",Ref7_RefAlarmState TINYINT,Ref7_ActiveState TINYINT,Ref8_RefAlarmState TINYINT,Ref8_ActiveState TINYINT,Ref9_RefAlarmState TINYINT,Ref9_ActiveState TINYINT,Ref10_RefAlarmState TINYINT,Ref10_ActiveState TINYINT" _
                   & ",Ref11_RefAlarmState TINYINT,Ref11_ActiveState TINYINT,Ref12_RefAlarmState TINYINT,Ref12_ActiveState TINYINT,Ref13_RefAlarmState TINYINT,Ref13_ActiveState TINYINT,Ref14_RefAlarmState TINYINT,Ref14_ActiveState TINYINT" _
                   & ",Ref15_RefAlarmState TINYINT,Ref15_ActiveState TINYINT,Ref16_RefAlarmState TINYINT,Ref16_ActiveState TINYINT, Primary Key(id))", pid_str, dti.NetId)
                tic.Add(strSql, Nothing)

                '创建当前工程某网络的历史数据表的时间索引
                strSql = String.Format("CREATE INDEX index_hDate_{0}_{1} On tbccHDData_{2}_{3}(hDate)", pid_str, dti.NetId, pid_str, dti.NetId)
                tic.Add(strSql, Nothing)

            End If
        Next

        If pi.DevTypeGroupList.Count > 0 Then '存在设备
            '创建当前工程某网络的历史数据索引表
            strSql = String.Format("Create TABLE tbccHistoryData_{0}(netID TINYINT,iYear integer,iMonth integer,iDay integer," _
            & "iHour integer,iMinute integer,iSecond integer,UploadTime datetime)", pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史数据索引表的时间索引
            strSql = String.Format("CREATE INDEX index_net_time_{0} On tbccHistoryData_{1}(netID,iYear,iMonth,iDay,iHour,iMinute,iSecond)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史报警数据表
            strSql = String.Format("Create TABLE tbccHDAlarmData_{0}(id integer ,netID TINYINT,pageIndex integer,RowIndex TINYINT" _
            & ",pageStartTime datetime,startTime datetime,A1 TINYINT,A2 TINYINT,A3 TINYINT,A4 TINYINT,A5 TINYINT,A6 TINYINT,A7 TINYINT,A8 TINYINT" _
            & ",A9 TINYINT,A10 TINYINT,A11 TINYINT,A12 TINYINT,A13 TINYINT,A14 TINYINT,A15 TINYINT,A16 TINYINT,A17 TINYINT,A18 TINYINT,A19 TINYINT,A20 TINYINT" _
            & ",A21 TINYINT,A22 TINYINT,A23 TINYINT,A24 TINYINT,AI1 float(5,2),AI2 float(5,2),AI3 float(5,2),AI4 float(5,2),AI5 float(5,2),AI6 float(5,2),AI7 float(5,2),AI8 float(5,2),AI9 float(5,2),AI10 float(5,2),AI11 float(5,2),AI12 float(5,2)" _
            & ",A25 TINYINT,A26 TINYINT,A27 TINYINT,A28 TINYINT,A29 TINYINT,A30 TINYINT,A31 TINYINT,A32 TINYINT,A33 TINYINT,A34 TINYINT,A35 TINYINT,A36 TINYINT,A37 TINYINT,A38 TINYINT,A39 TINYINT,A40 TINYINT,A41 TINYINT,A42 TINYINT,A43 TINYINT,A44 TINYINT" _
            & ",A45 TINYINT,A46 TINYINT,A47 TINYINT,A48 TINYINT,A49 TINYINT,A50 TINYINT,A51 TINYINT,A52 TINYINT,A53 TINYINT,A54 TINYINT,A55 TINYINT,A56 TINYINT,A57 TINYINT,A58 TINYINT,A59 TINYINT,A60 TINYINT,A61 TINYINT,A62 TINYINT,A63 TINYINT,A64 TINYINT" _
            & ",AI13 float(5,2),AI14 float(5,2),AI15 float(5,2),AI16 float(5,2),AI17 float(5,2),AI18 float(5,2),AI19 float(5,2),AI20 float(5,2),AI21 float(5,2),AI22 float(5,2),AI23 float(5,2),AI24 float(5,2),AI25 float(5,2),AI26 float(5,2),AI27 float(5,2)" _
            & ",AI28 float(5,2),AI29 float(5,2),AI30 float(5,2),AI31 float(5,2),AI32 float(5,2),Ref_Network_Alarm TINYINT,Ref1_LostPowerAlarm TINYINT,Ref1_DoorAlarm TINYINT,Ref2_LostPowerAlarm TINYINT,Ref2_DoorAlarm TINYINT" _
            & ",Ref3_LostPowerAlarm TINYINT,Ref3_DoorAlarm TINYINT,Ref4_LostPowerAlarm TINYINT,Ref4_DoorAlarm TINYINT,Ref5_DoorAlarm TINYINT,Ref6_DoorAlarm TINYINT,Ref7_DoorAlarm TINYINT,Ref8_DoorAlarm TINYINT,Ref1_JointActionOpenStatus TINYINT,Ref1_JointActionCloseStatus TINYINT,Ref1_JointAction_Output TINYINT,Ref1_DefrostStatus TINYINT" _
            & ",Ref2_JointActionOpenStatus TINYINT,Ref2_JointActionCloseStatus TINYINT,Ref2_JointAction_Output TINYINT,Ref2_DefrostStatus TINYINT,Ref3_JointActionOpenStatus TINYINT,Ref3_JointActionCloseStatus TINYINT,Ref3_JointAction_Output TINYINT,Ref3_DefrostStatus TINYINT,Ref4_JointActionOpenStatus TINYINT,Ref4_JointActionCloseStatus TINYINT,Ref4_JointAction_Output TINYINT,Ref4_DefrostStatus TINYINT," _
            & "Generator_Alarm TINYINT,CompressorSetFailure1_Alarm TINYINT,CompressorSetFailure2_Alarm TINYINT,CompressorSetFailure3_Alarm TINYINT,CompressorSetFailure4_Alarm TINYINT,CompressorFailure1_Alarm TINYINT,CompressorFailure2_Alarm TINYINT,CompressorFailure3_Alarm TINYINT,CompressorFailure4_Alarm TINYINT,DefrostStatus1_Alarm TINYINT,DefrostStatus2_Alarm TINYINT,DefrostStatus3_Alarm TINYINT,DefrostStatus4_Alarm TINYINT)", pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史报警数据表的时间索引
            strSql = String.Format("CREATE INDEX index_HDAlarmData_{0} On tbccHDAlarmData_{1}(netID,startTime,pageIndex,RowIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史报警索引数据表
            strSql = String.Format("Create TABLE tbccAlarmData_{0}(netID TINYINT,pageIndex integer,StartTime datetime" _
            & ",EndTime datetime,UploadTime datetime,Finished TINYINT)", pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史报警索引数据表的时间索引
            strSql = String.Format("CREATE INDEX index_AlarmData_{0} On tbccAlarmData_{1}(netID,pageIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            '20100915增加DI历史数据表
            strSql = String.Format("Create TABLE tbccDiData_{0}(netID TINYINT,pageIndex integer,StartTime datetime" _
            & ",EndTime datetime,UploadTime datetime,Finished TINYINT)", pid_str)
            tic.Add(strSql, Nothing)

            strSql = String.Format("CREATE INDEX index_DiData_{0} On tbccDiData_{1}(netID,pageIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            strSql = String.Format("Create TABLE tbccHDDiData_{0}(id integer ,netID TINYINT,pageIndex integer,RowIndex TINYINT" _
           & ",pageStartTime datetime,startTime datetime,Ref1_DoorState TINYINT,Ref2_DoorState TINYINT,Ref3_DoorState TINYINT,Ref4_DoorState TINYINT,Ref5_DoorState TINYINT,Ref6_DoorState TINYINT,Ref7_DoorState TINYINT,Ref8_DoorState TINYINT,Ref1_JointAction TINYINT,Ref2_JointAction TINYINT,Ref3_JointAction TINYINT,Ref4_JointAction TINYINT," _
             & "Ref1_Compressor_Input TINYINT,Ref2_Compressor_Input TINYINT,Ref3_Compressor_Input TINYINT,Ref4_Compressor_Input TINYINT,Ref1_Cooling_Input TINYINT,Ref2_Cooling_Input TINYINT,Ref3_Cooling_Input TINYINT,Ref4_Cooling_Input TINYINT,Ref1_DefrostStatus TINYINT,Ref2_DefrostStatus TINYINT,Ref3_DefrostStatus TINYINT,Ref4_DefrostStatus TINYINT,Ref1_JointActionClose TINYINT,Ref2_JointActionClose TINYINT,Ref3_JointActionClose TINYINT,Ref4_JointActionClose TINYINT,Ref1_JointActionOpen TINYINT,Ref2_JointActionOpen TINYINT,Ref3_JointActionOpen TINYINT,Ref4_JointActionOpen TINYINT)", pid_str)
            tic.Add(strSql, Nothing)

            strSql = String.Format("CREATE INDEX index_HDDiData_{0} On tbccHDDiData_{1}(netID,startTime,pageIndex,RowIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)


        End If

        '20100517李吉鹏修改支持制冷多工程导入
        Dim obj As Object


        '获取最大的CCAPDEV ID
        strSql = String.Format("select max(id) from tbccccapdevtype")
        obj = SqlHelper.ExecuteScalar(strSql, Nothing)
        Dim CCapDevId As Integer
        If obj Is Nothing OrElse IsDBNull(obj) Then
            CCapDevId = 0
        Else
            CCapDevId = CLng(obj)
        End If
        CCapDevId += 1

        '获取机组的最大ID
        strSql = String.Format("select max(id) from tbccCompressorSet")
        obj = SqlHelper.ExecuteScalar(strSql, Nothing)
        Dim tcsId As Integer
        If obj Is Nothing OrElse IsDBNull(obj) Then
            tcsId = 0
        Else
            tcsId = CLng(obj)
        End If
        tcsId += 1

        '获取最大的冷凝器 ID
        strSql = String.Format("select max(id) from tbccCondenser")
        obj = SqlHelper.ExecuteScalar(strSql, Nothing)
        Dim tconId As Integer
        If obj Is Nothing OrElse IsDBNull(obj) Then
            tconId = 0
        Else
            tconId = CLng(obj)
        End If
        tconId += 1

        '获取最大的冷风机 ID
        strSql = String.Format("select max(id) from tbccAirCooler")
        obj = SqlHelper.ExecuteScalar(strSql, Nothing)
        Dim tacId As Integer
        If obj Is Nothing OrElse IsDBNull(obj) Then
            tacId = 0
        Else
            tacId = CLng(obj)
        End If
        tacId += 1

        '获取最大的压缩机 ID
        strSql = String.Format("select max(id) from tbccCompressor")
        obj = SqlHelper.ExecuteScalar(strSql, Nothing)
        Dim tcId As Integer
        If obj Is Nothing OrElse IsDBNull(obj) Then
            tcId = 0
        Else
            tcId = CLng(obj)
        End If
        tcId += 1

        If pi.CcappDevList IsNot Nothing Then
            For Each item As CcapDevItem In pi.CcappDevList
                If pi.CcapCommonItem.CcapId = item.Id Then
                    pi.CcapCommonItem.CcapId = CCapDevId
                End If
                item.Id = CCapDevId
                CCapDevId += 1

                '增加制冷设备表信息
                strSql = String.Format("Insert into TbccCcapDevType(id,projectID,csNetid,DevType) Values('{0}','{1}','{2}','{3}') -- " & iTemp, item.Id, pi.ProjectID, item.NetId, item.DevType)
                tic.Add(strSql, Nothing)
                iTemp += 1

                If pi.CcapCommonItem.CcapId = item.Id Then
                    'pi.CcapCommonItem.NetId = CCapDevId
                    strSql = String.Format("Insert into tbccCcapPortSet(devId,CpsLostPowerAlarmPort,CpsBreakDownAlarmPort,CpsSoundAlarmPort) values('{0}','{1}','{2}','{3}') -- " & iTemp, pi.CcapCommonItem.CcapId, pi.CcapCommonItem.CcapLostPowerAlarmPort, pi.CcapCommonItem.CcapGeneratorStartAlarmPort, pi.CcapCommonItem.CcapSoundAlarmPort)
                    tic.Add(strSql, Nothing)
                    iTemp += 1
                End If
                ' strsql=string.Format("Insert into tbccCcapPortSet(devid,cpsLostPowerAlarmPort,CpsBreakDownAlarmPort) values({0},{1},{2}) --" & index,item.Id,item.




                For Each cs As CcapCompressorSetItem In item.CompressorSetGroupList   '机组表
                    For Each item_temp As CcapDevItem In pi.CcappDevList
                        For Each cd As CcapCondenserItem In item_temp.CondenserGroupList    '冷凝器
                            If cd.CsId = cs.Id Then
                                cd.CsId = tcsId
                            End If
                        Next
                        For Each ac As CcapAirCoolerItem In item_temp.AirCoolerGroupList   '冷风机
                            If ac.CsId = cs.Id Then
                                ac.CsId = tcsId
                            End If
                        Next
                    Next

                    cs.Id = tcsId
                    tcsId += 1

                    strSql = String.Format("Insert into tbccCompressorSet(id,Devid,csName,csType,csCount,RelId) values('{0}','{1}','{2}','{3}','{4}','{5}') -- " & iTemp, cs.Id, item.Id, cs.CompressorSetName, cs.CompressorSetType, cs.CompressorCount, cs.RelId)
                    tic.Add(strSql, Nothing)
                    iTemp += 1

                    '机组端口配置信息表
                    If cs.MultiCompressorSetPort IsNot Nothing Then
                        strSql = String.Format("Insert into tbcccompressorsetportset(csid,CsSuckPressAlarmPort,CsLowLiquidAlarmPort,CsLostPowerAlarmPort) values('{0}','{1}','{2}','{3}') -- " & iTemp, cs.Id, cs.MultiCompressorSetPort.CsSuckPressAlarmPort, cs.MultiCompressorSetPort.CsLowLiquidAlarmPort, cs.MultiCompressorSetPort.CsLostPowerAlarmPort)
                        tic.Add(strSql, Nothing)
                        iTemp += 1
                    End If

                    '冷凝机组端口配置信息表
                    If cs.SingleCompressorSetPort IsNot Nothing Then
                        strSql = String.Format("Insert into tbcccondensersetportset(csid,CsLostPowerAlarmPort,CsOverLoadAlarmPort,CsBreakDownAlarmPort) values('{0}','{1}','{2}','{3}') -- " & iTemp, cs.Id, cs.SingleCompressorSetPort.CsLostPowerAlarmPort, cs.SingleCompressorSetPort.CsOverLoadAlarmPort, cs.SingleCompressorSetPort.CsBreakDownAlarmPort)
                        tic.Add(strSql, Nothing)
                        iTemp += 1
                    End If



                    For Each cp As CcapCompressorItem In cs.CompressorGroupList   '压缩机信息表
                        cp.Id = tcId
                        tcId += 1
                        '压缩机机头
                        strSql = String.Format("Insert into tbccCompressor(id,csId,name,RelId) values('{0}','{1}','{2}','{3}') -- " & iTemp, cp.Id, cs.Id, cp.CompressorName, cp.RelId)
                        tic.Add(strSql, Nothing)
                        iTemp += 1

                        '压缩器端口信息
                        strSql = String.Format("Insert into tbccCompressorPortSet(cpId,cpLowPressAlarmPort,cpHighPressAlarmPort,cpOileAlarmPort,cpChargeTAlarmPort,cpOverLoadAlarmPort,cpActiveStatePort) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}') -- " & iTemp, cp.Id, cp.CompressorPort.cpLowPressAlarmPort, cp.CompressorPort.cpHighPressAlarmPort, cp.CompressorPort.cpOileAlarmPort, cp.CompressorPort.cpChargeTAlarmPort, cp.CompressorPort.cpOverLoadAlarmPort, cp.CompressorPort.cpActiveStatePort)
                        tic.Add(strSql, Nothing)
                        iTemp += 1
                    Next
                Next

                For Each cd As CcapCondenserItem In item.CondenserGroupList    '冷凝器

                    cd.Id = tconId
                    tconId += 1

                    strSql = String.Format("Insert into tbccCondenser(id,csNetid,csId,name,RelId) values('{0}','{1}','{2}','{3}','{4}') -- " & iTemp, cd.Id, item.NetId, cd.CsId, cd.CondenserName, cd.RelId)
                    tic.Add(strSql, Nothing)
                    iTemp += 1

                    strSql = String.Format("Insert into tbccCondenserPortSet(ceId,cePressPreAlarmPort) values('{0}','{1}') -- " & iTemp, cd.Id, cd.CondenserPort.cePressPreAlarmPort)
                    tic.Add(strSql, Nothing)
                    iTemp += 1
                Next


                For Each ac As CcapAirCoolerItem In item.AirCoolerGroupList   '冷风机
                    ac.Id = tacId
                    tacId += 1

                    strSql = String.Format("Insert into tbccAirCooler(id,csNetid,csId,name,RelId) values('{0}','{1}','{2}','{3}','{4}') -- " & iTemp, ac.Id, item.NetId, ac.CsId, ac.AirCoolerName, ac.RelId)
                    tic.Add(strSql, Nothing)
                    iTemp += 1

                    strSql = String.Format("Insert into tbccAirCoolerPortSet(acId,acDefPreAlarmPort) values('{0}','{1}') -- " & iTemp, ac.Id, ac.AirCoolerPort.acDefPreAlarmPort)
                    tic.Add(strSql, Nothing)
                    iTemp += 1
                Next

            Next


        End If



        Return SqlHelper.ExecuteTranstration(tic)

    End Function

    Public Shared Function Delete(ByVal pi As ProjectItem, ByVal netcount As Integer, ByVal nettype As Integer) As Integer

        Dim strSql As String
        Dim pid_str As String
        pid_str = Trim(pi.ProjectID).Replace("-", "_")
        Dim tic As New TBCC.Utility.TranstrationItem

        '删除工程信息总表中的数据
        strSql = String.Format("Delete From tbccProject Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程信息字典中的数据
        strSql = String.Format("Delete From tbccDictory Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程图表的数据
        strSql = String.Format("Delete From tbccProjectImages Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程图表中显示组件中的数据
        strSql = String.Format("Delete From tbccImageControls Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程类型数据
        strSql = String.Format("Delete From TbccDevType Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程冷库信息数据
        strSql = String.Format("Delete From TbccRefInfo Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程AI信息数据
        strSql = String.Format("Delete From TbccAiInfo Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除工程DI/DO信息数据
        strSql = String.Format("Delete From TbccDiDoInfo Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除设备自检数据
        strSql = String.Format("Delete From tbccCheckAlarm Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除参数校准数据
        strSql = String.Format("Delete From tbccCalibLog Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除历史报警文档数据数据
        strSql = String.Format("Delete From tbccHDAlarmDoc Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除IO离线配置端口
        strSql = String.Format("Delete From tbccIOInfo_Offline Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除IO离线配置参数
        strSql = String.Format("Delete From tbccIOParameter_Offline Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除制冷设备参数
        strSql = String.Format("delete from TbccCcapDevType where projectID='{0}' ", pi.ProjectID)
        tic.Add(strSql, Nothing)


        '删除IO离线配置端口
        strSql = String.Format("Delete From tbccIOInfo_Offlinecold Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除IO离线配置参数
        strSql = String.Format("Delete From tbccIOParameter_Offlinecold Where projectID='{0}'", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除启停数据表
        strSql = String.Format("delete from tbcchddatastartendpage where projectID='{0}' ", pi.ProjectID)
        tic.Add(strSql, Nothing)

        '删除手动上传数据表
        strSql = String.Format("delete from tbcchdmanualuploadrecord where projectID='{0}' ", pi.ProjectID)
        tic.Add(strSql, Nothing)


        If netcount > 0 OrElse nettype > 0 Then
            '删除当前工程某网络的历史数据表
            For i As Integer = 1 To netcount
                strSql = String.Format("Drop TABLE if exists tbccHDData_{0}_{1}", pid_str, i)
                tic.Add(strSql, Nothing)
            Next

            For j As Integer = 100 To nettype
                strSql = String.Format("Drop TABLE if exists tbccHDData_{0}_{1}", pid_str, j)
                tic.Add(strSql, Nothing)
            Next

            '删除当前工程某网络的历史索引数据表
            strSql = String.Format("Drop TABLE if exists tbccHistoryData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警数据表
            strSql = String.Format("Drop TABLE if exists tbccHDAlarmData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警索引数据表
            strSql = String.Format("Drop TABLE if exists tbccAlarmData_{0}", pid_str)
            tic.Add(strSql, Nothing)


            '20100915DI 历史数据显示
            '删除当前工程DI历史数据索引表
            strSql = String.Format("Drop TABLE if exists tbccHDDiData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程DI历史数据表
            strSql = String.Format("Drop TABLE if exists tbccDiData_{0}", pid_str)
            tic.Add(strSql, Nothing)

        End If

        Return SqlHelper.ExecuteTranstration(tic)

    End Function

    Public Shared Function GetProjectList() As IList(Of ProjectItem)
        Dim pl As IList(Of ProjectItem)
        pl = New List(Of ProjectItem)

        Dim strSql As String
        strSql = "Select * From TbccRefInfo"
        Dim ds1 As DataSet
        ds1 = TBCC.Utility.SqlHelper.ExecuteDataset(strSql, Nothing)
        If ds1.Tables(0).Columns.Contains("HDCurveTempLineUp") Then
        Else
            updatedate()
        End If

        strSql = "Select * From tbccProject"
        Dim ds2 As DataSet
        ds2 = TBCC.Utility.SqlHelper.ExecuteDataset(strSql, Nothing)
        If ds2.Tables(0).Columns.Contains("VersionNo") = True Then
        Else
            updatedate1()
        End If

        strSql = "Select * From tbccProject;Select * From tbccProjectImages;Select * From tbccImageControls;Select * From TbccDevType Order By Netid;Select * From TbccRefInfo;Select * From TbccDiDoInfo;Select * From TbccAiInfo;Select * From TbccDictory;Select * From tbccIOInfo_Offline;Select * From tbccIOParameter_Offline;Select * From TbccCcapDevType;Select * From tbccCompressorSet;Select * From tbcccompressor;Select * From tbcccondenser;Select * From tbccaircooler"

        Dim ds As DataSet
        ds = TBCC.Utility.SqlHelper.ExecuteDataset(strSql, Nothing)


        '查询错误
        If ds Is Nothing OrElse ds.Tables.Count = 0 Then
            Return Nothing
        End If

        Dim dtProject As DataTable
        dtProject = ds.Tables(0)

        Dim dtImage As DataTable
        dtImage = ds.Tables(1)

        dtProject.Columns.Add("iSort", GetType(Integer))
        For Each r As DataRow In dtProject.Rows
            r("iSort") = r("listNo")
        Next


        dtProject.DefaultView.Sort = "iSort asc"

        For Each r As DataRowView In dtProject.DefaultView
            Dim pi As New ProjectItem
            pi.ProjectID = r("projectID")
            pi.Phone = Convert.ToString(r("phoneNumber")).Trim()
            pi.ProjectName = r("ProjectName")
            pi.listNo = r("listNo")
            pi.Remark = Convert.ToString(r("Remark"))
            pi.ComNumber = r("ComNumber")
            pi.connectType = r("ConnectType")
            pi.AuthCode = r("AuthCode")
            pi.VersionNo = r("VersionNo")
            pi.ProjectType = r("ProjectType")
            pi.PhonePort = r("phonePort")
            pi.IPAddress = r("IPAddress")
            pi.IPPort = r("IPPort")


            Dim filter4 As String
            filter4 = String.Format("ProjectID='{0}'", pi.ProjectID)

            '工程字典信息

            Dim pdi As New ProjectDictoryItem()
            For Each r8 As DataRow In ds.Tables(7).Select(filter4) '当前字典每一个key&value
                Dim kvi As KeyValueItem = New KeyValueItem(r8("key"), r8("value"))
                pdi.DicList.Add(kvi)
            Next
            pi.DictoryItem = pdi

            Dim filter As String
            filter = String.Format("ProjectID='{0}'", pi.ProjectID)

            '*******************************************
            '图层增加排序 20080225
            Dim dv2 As New DataView(dtImage, filter, "listNo", DataViewRowState.CurrentRows)
            For Each r2 As DataRowView In dv2
                Dim pii As New ProjectImageItem()
                pii.projectID = pi.ProjectID
                pii.imageName = r2("imageName")
                pii.ImageOrder = r2("listNo")
                pii.imagePath = r2("imagePath")
                pii.ImageID = r2("imageID")

                Dim filter1 As String
                filter1 = String.Format("ProjectID='{0}' and ImageID='{1}'", pi.ProjectID, pii.ImageID)

                For Each r3 As DataRow In ds.Tables(2).Select(filter1) '当前图层对应的每一个显示标签
                    Dim ici As New ImgControlItem()
                    ici.cHeight = r3("cHeight")
                    ici.cLeft = r3("cLeft")
                    ici.cTop = r3("cTop")
                    ici.cWidth = r3("cWidth")
                    ici.ImageID = r3("ImageID")
                    ici.Netid = r3("Netid")
                    ici.PortNo = r3("PortNo")
                    ici.DataType = r3("DataType")
                    ici.ProjectID = r3("ProjectID")
                    ici.Refid = r3("Refid")
                    ici.TipMsg = r3("TipMsg")
                    ici.TitleMsg = r3("TitleMsg")
                    ici.UnitMsg = r3("UnitMsg")
                    pii.ImgControlItemGroupList.Add(ici)
                Next

                pi.imageList.Add(pii)
            Next

            '*******************************************

            '工程类型信息
            For Each r4 As DataRow In ds.Tables(3).Select(filter) '对每一个设备
                Dim dti As New DevTypeItem()
                dti.ProjectID = r4("projectID")
                dti.NetId = r4("Netid")
                dti.DevType = r4("DevType")
                dti.RefNum = r4("RefNum")

                Dim filter2 As String
                filter2 = String.Format("ProjectID='{0}' and Netid='{1}'", pi.ProjectID, dti.NetId)
                'Try


                For Each r5 As DataRow In ds.Tables(4).Select(filter2) '对每一个冷库
                    Dim rti As New RefTypeItem()
                    rti.ProjectID = r5("projectID")
                    rti.NetId = r5("Netid")
                    rti.RefId = r5("Refid")
                    rti.RealRefId = r5("RealRefId")
                    rti.RefName = r5("RefName")
                    rti.FloorType = r5("FloorType")
                    rti.FloorNo = r5("FloorNo")
                    rti.RefType = r5("RefType")
                    rti.HDCurveTempUp = r5("HDCurveTempUp")
                    rti.HDCurveTempDown = r5("HDCurveTempDown")
                    rti.HDCurveHumiUp = r5("HDCurveHumiUp")
                    rti.HDCurveHumiDown = r5("HDCurveHumiDown")




                    '**************************************************************
                    '20090616 李吉鹏增加 为增加温湿度基准线及控制显示功能
                    rti.HDCurveTempLineUp = r5("HDCurveTempLineUp")
                    rti.HDCurveTempLineDown = r5("HDCurveTempLineDown")

                    rti.HDCurveHumiLineUp = r5("HDCurveHumiLineUp")
                    rti.HDCurveHumiLineDown = r5("HDCurveHumiLineDown")

                    rti.HDCurveTempLineUpShow = CBool(r5("HDCurveTempLineUpShow"))
                    rti.HDCurveTempLineDownShow = CBool(r5("HDCurveTempLineDownShow"))

                    rti.HDCurveHumiLineUpShow = CBool(r5("HDCurveHumiLineUpShow"))
                    rti.HDCurveHumiLineDownShow = CBool(r5("HDCurveHumiLineDownShow"))
                    '******************************************************


                    Dim filter3 As String
                    filter3 = String.Format("ProjectID='{0}' and Netid='{1}' and Refid='{2}'", pi.ProjectID, dti.NetId, rti.RefId)

                    For Each r6 As DataRow In ds.Tables(5).Select(filter3) '对该冷库每一个DI/DO
                        Dim didopti As New DiDoPortTypeItem()
                        didopti.ProjectID = r6("projectID")
                        didopti.NetId = r6("Netid")
                        didopti.RefId = r6("Refid")
                        didopti.DoorStatusPort = r6("DoorStatusPort")
                        didopti.RefAlarmPort = r6("RefAlarmPort")
                        didopti.SoundAlarmPort = r6("SoundAlarmPort")
                        didopti.LostPowerPort = r6("LostPowerPort")
                        didopti.DoorStatusPort2 = r6("DoorStatusPort2")
                        didopti.JointActionPort = r6("JointActionPort")
                        didopti.JointActionOpen_Output_Nu = r6("JointActionOpen_Output_Nu")
                        didopti.JointActionClose_Output_Nu = r6("JointActionClose_Output_Nu")
                        didopti.JointAction_Output_Nu = r6("JointAction_Output_Nu")
                        didopti.DefrostStatus_Input_Nu = r6("DefrostStatus_Input_Nu")
                        didopti.GeneratorPreAlarm_Nu = r6("GeneratorPreAlarm")
                        didopti.Cooling_Input_Nu = r6("Cooling_Input_Nu")
                        didopti.CompressorSetFailure_Input_Nu = r6("CompressorSetFailure_Input_Nu")
                        didopti.CompressorFailure_Input_Nu = r6("CompressorFailure_Input_Nu")
                        didopti.DefrostTemp_Input_Nu = r6("DefrostTemp_Input_Nu")
                        didopti.Compressor_Input_Nu = r6("Compressor_Input_Nu")
                        rti.DiDoPortInfo = didopti
                    Next


                    For Each r7 As DataRow In ds.Tables(6).Select(filter3) '对该冷库每一个AI
                        Dim aipti As New AiPortTypeItem()
                        aipti.ProjectID = r7("ProjectID")
                        aipti.NetId = r7("Netid")
                        aipti.RefId = r7("Refid")
                        aipti.SeqPortNo = r7("SeqPortNo")
                        aipti.PortNo = r7("PortNo")
                        aipti.PortName = r7("PortName")
                        aipti.DataType = r7("DataType")
                        aipti.CurveChecked = r7("CurveChecked")
                        aipti.PortNoType = r7("PortNoType")
                        rti.AiPortTypeGroupList.Add(aipti)
                    Next


                    For Each r9 As DataRow In ds.Tables(8).Select(filter3) '对该冷库每一个IO
                        Dim ipti As New IOPortTypeItem()
                        ipti.ProjectID = r9("projectID")
                        ipti.NetId = r9("Netid")
                        ipti.RefId = r9("Refid")
                        ipti.SeqPortNo = r9("SeqPortNo")
                        ipti.PortType = r9("PortType")
                        ipti.PortNo = r9("PortNo")
                        ipti.PortName = r9("PortName")
                        ipti.DataType = r9("DataType")
                        ipti.PortNoType = r9("PortNoType")
                        rti.IOPortTypeGroupList.Add(ipti)
                    Next


                    For Each r10 As DataRow In ds.Tables(9).Select(filter3) '对该冷库IO参数
                        Dim ipi As New IOParameterItem()
                        ipi.ProjectID = r10("projectID")
                        ipi.Netid = r10("Netid")
                        ipi.Refid = r10("Refid")
                        ipi.AlarmTempHigh = r10("AlarmTempHigh")
                        ipi.AlarmTempLow = r10("AlarmTempLow")
                        ipi.AlarmHumiHigh = r10("AlarmHumiHigh")
                        ipi.AlarmHumiLow = r10("AlarmHumiLow")
                        ipi.DoorAlarmDelay = r10("DoorAlarmDelay")
                        ipi.DoorPreAlarmDelay = r10("DoorPreAlarmDelay")
                        ipi.LostAlarmDelay = r10("LostAlarmDelay")
                        ipi.LostPreAlarmDelay = r10("LostPreAlarmDelay")
                        ipi.TempHighAlarmDelay = r10("TempHighAlarmDelay")
                        ipi.TempHighPreDelay = r10("TempHighPreDelay")
                        ipi.TempLowAlarmDelay = r10("TempLowAlarmDelay")
                        ipi.TempLowPreDelay = r10("TempLowPreDelay")
                        ipi.HumiHighAlarmDelay = r10("HumiHighAlarmDelay")
                        ipi.HumiHighPreDelay = r10("HumiHighPreDelay")
                        ipi.HumiLowAlarmDelay = r10("HumiLowAlarmDelay")
                        ipi.HumiLowPreDelay = r10("HumiLowPreDelay")

                        If ds.Tables(9).Columns.Contains("AlarmHumiHighPer") Then    '项目中包含预警参数


                            '*********************************************************************************************
                            ipi.AlarmHumiHighPer = r10("AlarmHumiHighPer")
                            ipi.AlarmHumiLowPer = r10("AlarmHumiLowPer")
                            ipi.AlarmTempHighPer = r10("AlarmTempHighPer")
                            ipi.AlarmTempLowPer = r10("AlarmTempLowPer")
                            '*********************************************************************************************
                        Else
                        End If
                        If ds.Tables(9).Columns.Contains("Door2PreAlarmDelay") Then
                            ipi.Door2PreAlarmDelay = r10("Door2PreAlarmDelay")
                            ipi.Door2AlarmDelay = r10("door2AlarmDelay")
                            ipi.DoorCoalitionDelay = r10("DoorCoalitionDelay")
                            ipi.GeneratorPreAlarmDelayTime = r10("GeneratorPreAlarmDelayTime")

                        End If
                        rti.IOParameterItem = ipi
                    Next

                    dti.RefTypeGroupList.Add(rti)
                Next

                pi.DevTypeGroupList.Add(dti)
            Next

            Dim filter11 As String
            filter11 = String.Format("ProjectID='{0}'", pi.ProjectID)

            For Each r11 As DataRow In ds.Tables(10).Select(filter11) '对每一个设备
                Dim dticcap As New CcapDevItem()
                dticcap.Id = r11("id")
                dticcap.ProjectID = r11("projectID")
                dticcap.NetId = r11("csNetid")
                dticcap.DevType = r11("DevType")

                'Dim filter12 As String
                'filter12 = String.Format(" Devid='{0}'", dticcap.Id)

                'For Each r12 As DataRow In ds.Tables(11).Select(filter12) '对每一个机组
                '    Dim rti As New CcapCompressorSetItem()
                '    rti.Id = r12("id")
                '    rti.ProjectID = dti.ProjectID
                '    rti.NetId = r12("Devid")
                '    rti.CompressorSetName = r12("csName")
                '    rti.CompressorSetType = r12("csType")
                '    rti.CompressorCount = r12("csCount")
                '    dticcap.CompressorSetGroupList.Add(rti)

                '    Dim filter13 As String
                '    filter13 = String.Format("csId='{0}' ", rti.Id)
                '    For Each r13 As DataRow In ds.Tables(12).Select(filter13)   '每个压缩机
                '        Dim com As New CcapCompressorItem
                '        com.Id = r13("id")
                '        com.CompressorName = r13("name")
                '        com.CsId = r13("csId")
                '        rti.CompressorGroupList.Add(com)
                '    Next

                'Next

                'Dim filter14 As String
                'filter14 = String.Format(" csNetid='{0}'  ", dticcap.NetId)
                'For Each r14 As DataRow In ds.Tables(13).Select(filter14)
                '    Dim con As New CcapCondenserItem

                '    con.Id = r14("id")
                '    con.ProjectID = dti.ProjectID
                '    con.NetId = dti.NetId
                '    con.CsId = r14("csId")
                '    con.CondenserName = r14("name")
                '    dticcap.CondenserGroupList.Add(con)

                'Next
                'For Each r15 As DataRow In ds.Tables(14).Select(filter14)
                '    Dim air As New CcapAirCoolerItem

                '    air.Id = r15("id")
                '    air.ProjectID = dti.ProjectID
                '    air.NetId = dti.NetId
                '    air.CsId = r15("csId")
                '    air.AirCoolerName = r15("name")
                '    dticcap.AirCoolerGroupList.Add(air)

                'Next

                pi.CcappDevList.Add(dticcap)

            Next


            pl.Add(pi)
        Next

        Return pl

    End Function
    Public Shared Sub updatedate()
        Dim strSql As String
        Dim tic As New TBCC.Utility.TranstrationItem
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveTempLineUp integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveTempLineDown integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveHumiLineUp integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveHumiLineDown integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveTempLineUpShow integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveTempLineDownShow integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveHumiLineUpShow integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        strSql = String.Format("ALTER TABLE tbccrefinfo ADD COLUMN HDCurveHumiLineDownShow integer  DEFAULT 0 ")
        tic.Add(strSql, Nothing)
        SqlHelper.ExecuteTranstration(tic)

    End Sub

    Public Shared Sub updatedate1()
        Dim strSql As String
        Dim tic As New TBCC.Utility.TranstrationItem
        strSql = String.Format("ALTER TABLE tbccProject ADD COLUMN versionno text  DEFAULT null ")
        tic.Add(strSql, Nothing)
        SqlHelper.ExecuteTranstration(tic)
    End Sub

    '刷新当前工程所有信息
    Public Shared Function RefreshCurProjectList(ByVal projectid As String) As ProjectItem

        Dim pi As ProjectItem = Nothing

        Dim strSql As String
        strSql = "Select * From tbccProject;Select * From tbccProjectImages;Select * From tbccImageControls;Select * From TbccDevType Order By Netid;Select * From TbccRefInfo;Select * From TbccDiDoInfo;Select * From TbccAiInfo;Select * From tbccDictory;Select * From tbccIOInfo_Offline;Select * From tbccIOParameter_Offline;" _
                 & "Select * From TbccCcapDevType;Select * From tbccCompressorSet;Select * From tbcccompressor;Select * From tbcccondenser;Select * From tbccaircooler;Select * From tbccCcapPortSet where CpsLostPowerAlarmPort<>0;select * from tbccCondenserSetPortSet;select * from tbccCompressorSetPortSet;select * from tbccCompressorPortSet;select * from tbccCondenserPortSet;select * from tbccAirCoolerPortSet;select * from tbccioinfo_offlinecold;select * from tbccioparameter_offlinecold"

        Dim ds As DataSet
        ds = TBCC.Utility.SqlHelper.ExecuteDataset(strSql, Nothing)

        '查询错误
        If ds Is Nothing OrElse ds.Tables.Count = 0 Then
            Return Nothing
        End If

        Dim dtProject As DataTable
        dtProject = ds.Tables(0)

        Dim dtImage As DataTable
        dtImage = ds.Tables(1)

        dtProject.Columns.Add("iSort", GetType(Integer))
        For Each r As DataRow In dtProject.Rows
            r("iSort") = r("listNo")
        Next

        dtProject.DefaultView.Sort = "iSort asc"

        For Each r As DataRowView In dtProject.DefaultView
            If r("projectID") <> projectid Then
                Continue For
            End If

            pi = New ProjectItem

            pi.ProjectID = r("projectID")
            pi.Phone = Convert.ToString(r("phoneNumber")).Trim()
            pi.ProjectName = r("ProjectName")
            pi.listNo = r("listNo")
            pi.Remark = Convert.ToString(r("Remark"))
            pi.ComNumber = r("ComNumber")
            pi.connectType = r("ConnectType")
            pi.AuthCode = r("AuthCode")
            pi.VersionNo = r("VersionNo")
            pi.ProjectType = ProjectService.RefreshProjectType(projectid) 'r("ProjectType")
            pi.PhonePort = r("phonePort")
            pi.IPAddress = r("IPAddress")
            pi.IPPort = r("IPPort")


            '工程字典信息
            Dim filter4 As String
            filter4 = String.Format("ProjectID='{0}'", pi.ProjectID)

            Dim pdi As New ProjectDictoryItem()
            For Each r8 As DataRow In ds.Tables(7).Select(filter4) '当前字典每一个key&value
                Dim kvi As KeyValueItem = New KeyValueItem(r8("key"), r8("value"))
                pdi.DicList.Add(kvi)
            Next
            pi.DictoryItem = pdi

            Dim filter As String
            filter = String.Format("ProjectID='{0}'", pi.ProjectID)

            '*******************************************
            '图层增加排序 
            Dim dv2 As New DataView(dtImage, filter, "listNo", DataViewRowState.CurrentRows)
            For Each r2 As DataRowView In dv2
                Dim pii As New ProjectImageItem()
                pii.projectID = pi.ProjectID
                pii.imageName = r2("imageName")
                pii.ImageOrder = r2("listNo")
                pii.imagePath = r2("imagePath")
                pii.ImageID = r2("imageID")

                Dim filter1 As String
                filter1 = String.Format("ProjectID='{0}' and ImageID='{1}'", pi.ProjectID, pii.ImageID)

                For Each r3 As DataRow In ds.Tables(2).Select(filter1) '当前图层对应的每一个显示标签
                    Dim ici As New ImgControlItem()
                    ici.cHeight = r3("cHeight")
                    ici.cLeft = r3("cLeft")
                    ici.cTop = r3("cTop")
                    ici.cWidth = r3("cWidth")
                    ici.ImageID = r3("ImageID")
                    ici.Netid = r3("Netid")
                    ici.PortNo = r3("PortNo")
                    ici.DataType = r3("DataType")
                    ici.ProjectID = r3("ProjectID")
                    ici.Refid = r3("Refid")
                    ici.TipMsg = r3("TipMsg")
                    ici.TitleMsg = r3("TitleMsg")
                    ici.UnitMsg = r3("UnitMsg")
                    pii.ImgControlItemGroupList.Add(ici)
                Next

                pi.imageList.Add(pii)
            Next

            '*******************************************

            '工程类型信息
            For Each r4 As DataRow In ds.Tables(3).Select(filter) '对每一个设备
                Dim dti As New DevTypeItem()
                dti.ProjectID = r4("projectID")
                dti.NetId = r4("Netid")
                dti.DevType = r4("DevType")
                dti.RefNum = r4("RefNum")
                dti.DevAppType = r4("DevAppType")

                Dim filter2 As String
                filter2 = String.Format("ProjectID='{0}' and Netid='{1}'", pi.ProjectID, dti.NetId)

                For Each r5 As DataRow In ds.Tables(4).Select(filter2) '对每一个冷库
                    Dim rti As New RefTypeItem()
                    rti.ProjectID = r5("projectID")
                    rti.NetId = r5("Netid")
                    rti.RefId = r5("Refid")
                    rti.RealRefId = r5("RealRefId")
                    rti.RefName = r5("RefName")
                    rti.FloorType = r5("FloorType")
                    rti.FloorNo = r5("FloorNo")
                    rti.RefType = r5("RefType")
                    rti.HDCurveTempUp = r5("HDCurveTempUp")
                    rti.HDCurveTempDown = r5("HDCurveTempDown")
                    rti.HDCurveHumiUp = r5("HDCurveHumiUp")
                    rti.HDCurveHumiDown = r5("HDCurveHumiDown")

                    '**************************************************************
                    '20090616 李吉鹏增加 为增加温湿度基准线及控制显示功能


                    rti.HDCurveTempLineUpShow = CBool(r5("HDCurveTempLineUpShow"))
                    rti.HDCurveTempLineDownShow = CBool(r5("HDCurveTempLineDownShow"))

                    rti.HDCurveHumiLineUpShow = CBool(r5("HDCurveHumiLineUpShow"))
                    rti.HDCurveHumiLineDownShow = CBool(r5("HDCurveHumiLineDownShow"))
                    rti.HDCurveTempLineUp = r5("HDCurveTempLineUp")
                    rti.HDCurveTempLineDown = r5("HDCurveTempLineDown")

                    rti.HDCurveHumiLineUp = r5("HDCurveHumiLineUp")
                    rti.HDCurveHumiLineDown = r5("HDCurveHumiLineDown")
                    '*********************************************************************
                    Dim filter3 As String
                    filter3 = String.Format("ProjectID='{0}' and Netid='{1}' and Refid='{2}'", pi.ProjectID, dti.NetId, rti.RefId)

                    For Each r6 As DataRow In ds.Tables(5).Select(filter3) '对该冷库每一个DI/DO
                        Dim didopti As New DiDoPortTypeItem()
                        didopti.ProjectID = r6("projectID")
                        didopti.NetId = r6("Netid")
                        didopti.RefId = r6("Refid")
                        didopti.DoorStatusPort = r6("DoorStatusPort")
                        didopti.RefAlarmPort = r6("RefAlarmPort")
                        didopti.SoundAlarmPort = r6("SoundAlarmPort")
                        didopti.LostPowerPort = r6("LostPowerPort")
                        didopti.DoorStatusPort2 = r6("DoorStatusPort2")
                        didopti.JointActionPort = r6("JointActionPort")
                        didopti.JointActionOpen_Output_Nu = r6("JointActionOpen_Output_Nu")
                        didopti.JointActionClose_Output_Nu = r6("JointActionClose_Output_Nu")
                        didopti.JointAction_Output_Nu = r6("JointAction_Output_Nu")
                        didopti.DefrostStatus_Input_Nu = r6("DefrostStatus_Input_Nu")
                        didopti.GeneratorPreAlarm_Nu = r6("GeneratorPreAlarm")
                        didopti.Cooling_Input_Nu = r6("Cooling_Input_Nu")
                        didopti.CompressorSetFailure_Input_Nu = r6("CompressorSetFailure_Input_Nu")
                        didopti.CompressorFailure_Input_Nu = r6("CompressorFailure_Input_Nu")
                        didopti.DefrostTemp_Input_Nu = r6("DefrostTemp_Input_Nu")
                        didopti.Compressor_Input_Nu = r6("Compressor_Input_Nu")
                        rti.DiDoPortInfo = didopti
                    Next


                    For Each r7 As DataRow In ds.Tables(6).Select(filter3) '对该冷库每一个AI
                        Dim aipti As New AiPortTypeItem()
                        aipti.ProjectID = r7("ProjectID")
                        aipti.NetId = r7("Netid")
                        aipti.RefId = r7("Refid")
                        aipti.SeqPortNo = r7("SeqPortNo")
                        aipti.PortNo = r7("PortNo")
                        aipti.PortName = r7("PortName")
                        aipti.DataType = r7("DataType")
                        aipti.CurveChecked = r7("CurveChecked")
                        aipti.PortNoType = r7("PortNoType")
                        rti.AiPortTypeGroupList.Add(aipti)
                    Next


                    For Each r9 As DataRow In ds.Tables(8).Select(filter3) '对该冷库每一个IO
                        Dim ipti As New IOPortTypeItem()
                        ipti.ProjectID = r9("projectID")
                        ipti.NetId = r9("Netid")
                        ipti.RefId = r9("Refid")
                        ipti.SeqPortNo = r9("SeqPortNo")
                        ipti.PortType = r9("PortType")
                        ipti.PortNo = r9("PortNo")
                        ipti.PortName = r9("PortName")
                        ipti.DataType = r9("DataType")
                        ipti.PortNoType = r9("PortNoType")
                        rti.IOPortTypeGroupList.Add(ipti)
                    Next

                    'Dim filter18 As String
                    'filter18 = String.Format("ProjectID='{0}'", pi.ProjectID)

                    For Each r17 As DataRow In ds.Tables(21).Select(filter3)    '离线IO配置表
                        Dim ipti As New IOPortTypeItem()
                        ipti.ProjectID = r17("projectID")
                        ipti.NetId = r17("Netid")
                        ipti.RefId = r17("Refid")
                        ipti.SeqPortNo = r17("SeqPortNo")
                        ipti.PortType = r17("PortType")
                        ipti.PortNo = r17("PortNo")
                        ipti.PortName = r17("PortName")
                        ipti.DataType = r17("DataType")
                        'ipti.PortNoType = r17("PortNoType")
                        rti.IOPortTypeGroupList.Add(ipti)



                    Next

                    'Dim filter19 As String
                    'filter19 = String.Format("ProjectID='{0}'", pi.ProjectID)



                    For Each r10 As DataRow In ds.Tables(9).Select(filter3) '对该冷库IO参数
                        Dim ipi As New IOParameterItem()
                        ipi.ProjectID = r10("projectID")
                        ipi.Netid = r10("Netid")
                        ipi.Refid = r10("Refid")
                        ipi.AlarmTempHigh = r10("AlarmTempHigh")
                        ipi.AlarmTempLow = r10("AlarmTempLow")
                        ipi.AlarmHumiHigh = r10("AlarmHumiHigh")
                        ipi.AlarmHumiLow = r10("AlarmHumiLow")
                        ipi.DoorAlarmDelay = r10("DoorAlarmDelay")
                        ipi.DoorPreAlarmDelay = r10("DoorPreAlarmDelay")
                        ipi.LostAlarmDelay = r10("LostAlarmDelay")
                        ipi.LostPreAlarmDelay = r10("LostPreAlarmDelay")
                        ipi.TempHighAlarmDelay = r10("TempHighAlarmDelay")
                        ipi.TempHighPreDelay = r10("TempHighPreDelay")
                        ipi.TempLowAlarmDelay = r10("TempLowAlarmDelay")
                        ipi.TempLowPreDelay = r10("TempLowPreDelay")
                        ipi.HumiHighAlarmDelay = r10("HumiHighAlarmDelay")
                        ipi.HumiHighPreDelay = r10("HumiHighPreDelay")
                        ipi.HumiLowAlarmDelay = r10("HumiLowAlarmDelay")
                        ipi.HumiLowPreDelay = r10("HumiLowPreDelay")
                        ipi.GeneratorPreAlarmDelayTime = r10("GeneratorPreAlarmDelayTime")

                        If ds.Tables(9).Columns.Contains("AlarmHumiHighPer") Then    '项目中包含预警参数
                            '*********************************************************************************************
                            ipi.AlarmHumiHighPer = r10("AlarmHumiHighPer")
                            ipi.AlarmHumiLowPer = r10("AlarmHumiLowPer")
                            ipi.AlarmTempHighPer = r10("AlarmTempHighPer")
                            ipi.AlarmTempLowPer = r10("AlarmTempLowPer")
                            '*********************************************************************************************
                        Else
                        End If

                        If ds.Tables(9).Columns.Contains("Door2PreAlarmDelay") Then
                            ipi.Door2PreAlarmDelay = r10("Door2PreAlarmDelay")
                            ipi.Door2AlarmDelay = r10("door2AlarmDelay")
                            ipi.DoorCoalitionDelay = r10("DoorCoalitionDelay")

                        End If


                        For Each r18 As DataRow In ds.Tables(22).Select(filter3)    '离线IO参数配置表

                            ipi.JointActionOpen_CloseDwLimit = r18("JointActionOpen_CloseDwLimit")
                            ipi.JointActionClose_CloseDwLimit = r18("JointActionClose_CloseDwLimit")

                            ipi.JointActionClose_CloseLimit = r18("JointActionClose_CloseLimit")
                            ipi.JointActionOpen_CloseUpLimit = r18("JointActionOpen_CloseUpLimit")

                            ipi.CompressorFailurePreAlarm_DelayTime = r18("CompressorFailurePreAlarm_DelayTime")
                            ipi.CompressorSetFailurePreAlarm_DelayTime = r18("CompressorSetFailurePreAlarm_DelayTime")
                            ipi.DefrostPreAlarm_DelayTime = r18("DefrostPreAlarm_DelayTime")



                        Next


                        rti.IOParameterItem = ipi
                    Next

                    dti.RefTypeGroupList.Add(rti)

                Next

                pi.DevTypeGroupList.Add(dti)
            Next


            Dim filter11 As String
            filter11 = String.Format("ProjectID='{0}'", pi.ProjectID)

            For Each r11 As DataRow In ds.Tables(10).Select(filter11) '对每一个设备
                Dim dticcap As New CcapDevItem()
                dticcap.Id = r11("id")
                dticcap.ProjectID = r11("projectID")
                dticcap.NetId = r11("csNetid")
                dticcap.DevType = r11("DevType")

                Dim filter12 As String
                filter12 = String.Format(" Devid='{0}'", dticcap.Id)


                For Each r12 As DataRow In ds.Tables(11).Select(filter12) '对每一个机组
                    Dim rti As New CcapCompressorSetItem()
                    rti.Id = r12("id")
                    rti.ProjectID = dticcap.ProjectID
                    rti.NetId = r12("Devid")
                    rti.CompressorSetName = r12("csName")
                    rti.CompressorSetType = r12("csType")
                    rti.CompressorCount = r12("csCount")
                    rti.RelId = r12("RelId")


                    Dim filter13 As String
                    filter13 = String.Format("csId='{0}' ", rti.Id)

                    For Each r17 As DataRow In ds.Tables(16).Select(filter13)


                        rti.SingleCompressorSetPort.CsId = r17("csId")
                        rti.SingleCompressorSetPort.CsBreakDownAlarmPort = r17("CsBreakDownAlarmPort")
                        rti.SingleCompressorSetPort.CsOverLoadAlarmPort = r17("CsOverLoadAlarmPort")
                        rti.SingleCompressorSetPort.CsLostPowerAlarmPort = r17("CsLostPowerAlarmPort")

                    Next
                    For Each r18 As DataRow In ds.Tables(17).Select(filter13)
                        rti.MultiCompressorSetPort.CsId = r18("csId")
                        rti.MultiCompressorSetPort.CsLowLiquidAlarmPort = r18("CsLowLiquidAlarmPort")
                        rti.MultiCompressorSetPort.CsSuckPressAlarmPort = r18("CsSuckPressAlarmPort")
                        rti.MultiCompressorSetPort.CsLostPowerAlarmPort = r18("CsLostPowerAlarmPort")

                    Next



                    For Each r13 As DataRow In ds.Tables(12).Select(filter13)   '每个压缩机
                        Dim com As New CcapCompressorItem
                        com.Id = r13("id")
                        com.CompressorName = r13("name")
                        com.CsId = r13("csId")
                        com.RelId = r13("RelId")

                        Dim filter15 As String
                        filter15 = String.Format(" cpId='{0}'  ", com.Id)
                        For Each r19 As DataRow In ds.Tables(18).Select(filter15)     '压缩机端口
                            com.CompressorPort.CpId = r19("cpId")
                            com.CompressorPort.cpChargeTAlarmPort = r19("cpChargeTAlarmPort")
                            com.CompressorPort.cpHighPressAlarmPort = r19("cpHighPressAlarmPort")
                            com.CompressorPort.cpLowPressAlarmPort = r19("cpLowPressAlarmPort")
                            com.CompressorPort.cpOileAlarmPort = r19("cpOileAlarmPort")
                            com.CompressorPort.cpOverLoadAlarmPort = r19("cpOverLoadAlarmPort")
                            com.CompressorPort.cpActiveStatePort = r19("cpActiveStatePort")

                        Next


                        rti.CompressorGroupList.Add(com)
                    Next

                    dticcap.CompressorSetGroupList.Add(rti)

                Next

                Dim filter14 As String
                filter14 = String.Format(" csNetid='{0}'  ", dticcap.NetId)
                For Each r14 As DataRow In ds.Tables(13).Select(filter14)
                    Dim con As New CcapCondenserItem

                    con.Id = r14("id")
                    con.ProjectID = dticcap.ProjectID
                    con.NetId = dticcap.NetId
                    con.CsId = r14("csId")
                    con.CondenserName = r14("name")
                    con.RelId = r14("RelId")

                    Dim filter16 As String
                    filter16 = String.Format(" ceId='{0}'  ", con.Id)
                    For Each r20 As DataRow In ds.Tables(19).Select(filter16)
                        con.CondenserPort.CeId = r20("ceId")
                        con.CondenserPort.cePressPreAlarmPort = r20("cePressPreAlarmPort")

                    Next


                    dticcap.CondenserGroupList.Add(con)

                Next
                For Each r15 As DataRow In ds.Tables(14).Select(filter14)
                    Dim air As New CcapAirCoolerItem

                    air.Id = r15("id")
                    air.ProjectID = dticcap.ProjectID
                    air.NetId = dticcap.NetId
                    air.CsId = r15("csId")
                    air.AirCoolerName = r15("name")
                    air.RelId = r15("RelId")


                    Dim filter17 As String
                    filter17 = String.Format(" acId='{0}'  ", air.Id)
                    For Each r21 As DataRow In ds.Tables(20).Select(filter17)
                        air.AirCoolerPort.AcId = r21("acId")
                        air.AirCoolerPort.acDefPreAlarmPort = r21("acDefPreAlarmPort")

                    Next


                    dticcap.AirCoolerGroupList.Add(air)

                Next

                ' For Each r16 As DataRow In ds.Tables(15).Select(filter12)   '全局端口表

                pi.CcappDevList.Add(dticcap)

            Next
            For Each r16 As DataRow In ds.Tables(15).Rows    '全局端口表

                pi.CcapCommonItem.CcapId = r16("Devid")
                pi.CcapCommonItem.CcapLostPowerAlarmPort = r16("CpsLostPowerAlarmPort")
                pi.CcapCommonItem.CcapGeneratorStartAlarmPort = r16("CpsBreakDownAlarmPort")
                pi.CcapCommonItem.CcapSoundAlarmPort = r16("CpsSoundAlarmPort")
                ' pi.CcapCommonItemInfoList.Add(comport)


            Next


          



        Next

        Return pi

    End Function
    ''' <summary>
    ''' 根据当前工程配置更新工程类型
    ''' </summary>
    ''' <param name="pid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function RefreshProjectType(ByVal pid As String) As Integer

        Dim ProType As Integer
        Dim WType As Integer
        Dim CcapType As Integer
        Dim strSql As String

        Dim tic As New TBCC.Utility.TranstrationItem

        '查询当前工程中是否包含仓储设备
        WType = DevTypeService.GetWType(pid)

        '查询当前工程中是否包含制冷设备
        CcapType = CcapDevItemService.GetCcapDevType(pid)


        '根据工程情况更新工程类型
        If WType <> 0 Then
            Select Case CcapType
                Case 1
                    ProType = 5    '混合制冷8DI
                Case 2
                    ProType = 7  '混合制冷24DI
                Case Else
                    ProType = 1   '独立仓储系统
            End Select

        Else
            Select Case CcapType

                Case 1
                    ProType = 4    '独立制冷8DI
                Case 2
                    ProType = 6  '独立制冷24DI

                Case Else

                    ProType = 0   '无工程配置

            End Select
        End If

        If MainForm.pi.ProjectType <> ProType Then
            MainForm.pi.ProjectType = ProType

            strSql = String.Format("Update tbccProject Set ProjectType='{0}' where projectID='{1}'", ProType, pid)

            tic.Add(strSql, Nothing)

            SqlHelper.ExecuteTranstration(tic)

        End If
        Return ProType

    End Function
    ''' <summary>
    ''' 返回工程中是否存在相同工程ID
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GetPrjID(ByVal pi As String) As Boolean
        Dim strSql As String
        strSql = "Select COUNT(projectID) from tbccDevType where projectID=?p0"

        Dim p(0) As MySql.Data.MySqlClient.MySqlParameter
        p(0) = New MySql.Data.MySqlClient.MySqlParameter
        p(0).ParameterName = "p0" : p(0).Value = pi


        Dim obj As Object
        obj = SqlHelper.ExecuteScalar(strSql, p)

        If obj Is Nothing OrElse IsDBNull(obj) OrElse CInt(obj) = 0 Then
            Return False
        Else
            Return True
        End If

    End Function
    ''' <summary>
    ''' 自动加载仓储信息
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Sub ExportProjectInfo()
        Dim dti As DevTypeItem = Nothing
        Dim m_pi As ProjectItem
        Dim FileName() As String
        Dim str As String
        Dim loadproject As Boolean
        str = Application.StartupPath
        Try
            '判断是否需要加载仓储工程
            loadproject = IIf(KeyValuePairClass.GetValue1("loadstorageproject").Equals("0"), True, False)

            If loadproject Then
            Else
                Exit Sub
            End If

        Catch ex As Exception

        End Try
        

        FileName = Directory.GetFiles(str)
        For Each str1 As String In FileName
            If str1.Contains(".tbl") Then

                Dim f As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
                'Dim s As New IO.FileStream(frm.FileName, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)
                Dim s As New IO.FileStream(str1, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.None)

                Try

                    m_pi = CType(f.Deserialize(s), ProjectItem)
                    If True = ProjectService.UpdatePrjDataToDb(m_pi, ProjectService.DevTypeMaxNetid(m_pi.ProjectID, 1), ProjectService.DevTypeMaxNetid(m_pi.ProjectID, 16)) Then '将工程信息更新到数据库
                        '更新加载仓储工程字段值
                        KeyValuePairClass.SetValue1("loadstorageproject", 1)

                    End If
                Catch ex As Exception
                    ' msg.ShowError(ex.Message)
                    Exit Sub
                Finally
                    s.Close()
                End Try

            End If
        Next




    End Sub
#Region "设备类型配置功能"
    '为设备类型配置提供获取当前设备和冷库名称等信息的功能
    Public Shared Function GetDevRefTypeList(ByVal pi As ProjectItem) As IList(Of DevTypeItem)
        Dim dtil As IList(Of DevTypeItem)
        dtil = New List(Of DevTypeItem)

        Dim strSql As String
        strSql = "Select * From TbccDevType order by Netid;Select * From TbccRefInfo order by Netid,refid"

        Dim ds As DataSet
        ds = TBCC.Utility.SqlHelper.ExecuteDataset(strSql, Nothing)

        '查询错误
        If ds Is Nothing OrElse ds.Tables.Count = 0 Then
            Return Nothing
        End If

        Dim filter1 As String
        filter1 = String.Format("ProjectID='{0}'", pi.ProjectID)

        For Each r1 As DataRow In ds.Tables(0).Select(filter1) '对每一个设备
            Dim dti As New DevTypeItem()
            dti.ProjectID = r1("projectID")
            dti.NetId = r1("Netid")
            dti.DevType = r1("DevType")
            dti.RefNum = r1("RefNum")
            dti.DevAppType = r1("DevAppType")

            Dim filter2 As String
            filter2 = String.Format("ProjectID='{0}' and Netid='{1}'", pi.ProjectID, dti.NetId)

            For Each r2 As DataRow In ds.Tables(1).Select(filter2) '对每一个冷库
                Dim rti As New RefTypeItem()
                rti.ProjectID = r2("projectID")
                rti.RefName = r2("Netid")
                rti.RefId = r2("Refid")
                rti.RealRefId = r2("RealRefId")
                rti.RefName = r2("RefName")
                rti.FloorType = r2("FloorType")
                rti.FloorNo = r2("FloorNo")
                rti.RefType = r2("RefType")
                rti.HDCurveTempUp = r2("HDCurveTempUp")
                rti.HDCurveTempDown = r2("HDCurveTempDown")
                rti.HDCurveHumiUp = r2("HDCurveHumiUp")
                rti.HDCurveHumiDown = r2("HDCurveHumiDown")


                '**************************************************************
                '20090616 李吉鹏增加 为增加温湿度基准线及控制显示功能
                rti.HDCurveTempLineUp = r2("HDCurveTempLineUp")
                rti.HDCurveTempLineDown = r2("HDCurveTempLineDown")

                rti.HDCurveHumiLineUp = r2("HDCurveHumiLineUp")
                rti.HDCurveHumiLineDown = r2("HDCurveHumiLineDown")

                rti.HDCurveTempLineUpShow = CBool(r2("HDCurveTempLineUpShow"))
                rti.HDCurveTempLineDownShow = CBool(r2("HDCurveTempLineDownShow"))

                rti.HDCurveHumiLineUpShow = CBool(r2("HDCurveHumiLineUpShow"))
                rti.HDCurveHumiLineDownShow = CBool(r2("HDCurveHumiLineDownShow"))
                '***********************************************************************
                dti.RefTypeGroupList.Add(rti)
            Next

            dtil.Add(dti)
        Next

        Return dtil

    End Function

    'ok
    '为设备类型配置提供增加功能 
    'netcount:当前工程已经配置的网络设备的数量
    Public Shared Function AddDevRefTypeList(ByVal item As DevTypeItem, ByVal netcount As Integer) As Boolean
        Dim strSql As String
        Dim pid_str As String

        pid_str = Trim(item.ProjectID).Replace("-", "_")


        strSql = "Insert into TbccDevType(projectID,Netid,DevType,RefNum,devAppType) Values(?p0,?p1,?p2,?p3,?p4)"

        Dim p1(4) As System.Data.Common.DbParameter

        p1(0) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(0).ParameterName = "p0" : p1(0).Value = item.ProjectID

        p1(1) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(1).ParameterName = "p1" : p1(1).Value = item.NetId

        p1(2) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(2).ParameterName = "p2" : p1(2).Value = item.DevType

        p1(3) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(3).ParameterName = "p3" : p1(3).Value = item.RefNum

        p1(4) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(4).ParameterName = "p4" : p1(4).Value = item.DevAppType

        Dim tic As New TBCC.Utility.TranstrationItem
        tic.Add(strSql, p1)

        '**************************************************************
        '20090616 李吉鹏增加 为增加温湿度基准线及控制显示功能 增加字段
        For Each rti As RefTypeItem In item.RefTypeGroupList
            strSql = String.Format("Insert into TbccRefInfo(projectID,Netid,Refid,RealRefId,RefName," & _
                                        "HDCurveTempUp,HDCurveTempDown,HDCurveHumiUp,HDCurveHumiDown,HdCurveTempLineUp," & _
                                        "HdCurveTempLineDown,HDCurveHumiLineUp,HDCurveHumiLineDown," & _
                                        "HDCurveTempLineUpShow,HDCurveTempLineDownShow,HDCurveHumiLineUpShow,HDCurveHumiLineDownShow,FloorType,FloorNo,RefType)" & _
                                        " Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}')", _
                                         item.ProjectID, item.NetId, rti.RefId, rti.RealRefId, rti.RefName, rti.HDCurveTempUp, rti.HDCurveTempDown, rti.HDCurveHumiUp, rti.HDCurveHumiDown, _
                                         rti.HDCurveTempLineUp, rti.HDCurveTempLineDown, rti.HDCurveHumiLineUp, rti.HDCurveHumiLineDown, _
                                          IIf(rti.HDCurveTempLineUpShow, 1, 0), IIf(rti.HDCurveTempLineDownShow, 1, 0), IIf(rti.HDCurveHumiLineUpShow, 1, 0), IIf(rti.HDCurveHumiLineDownShow, 1, 0), rti.FloorType, rti.FloorNo, rti.RefType)
            tic.Add(strSql, Nothing)
            '******************************************************************************************

        Next

        If item.DevAppType = 17 OrElse item.DevAppType = 1 Then

            '创建当前工程某网络的历史数据表
            strSql = String.Format("Create TABLE tbccHDData_{0}_{1}(id bigint not null auto_increment,hDate datetime,Uploadtime datetime,AI1 float(5,2),AI2 float(5,2),AI3 float(5,2)" _
               & ",AI4 float(5,2),AI5 float(5,2),AI6 float(5,2),AI7 float(5,2),AI8 float(5,2),AI9 float(5,2),AI10 float(5,2),AI11 float(5,2),AI12 float(5,2)" _
               & ",Ref1_RefAlarmState TINYINT,Ref1_LostPowerState TINYINT,Ref1_SoundOutputState TINYINT,Ref1_DoorState TINYINT,Ref1_ActiveState TINYINT" _
               & ",Ref2_RefAlarmState TINYINT,Ref2_LostPowerState TINYINT,Ref2_SoundOutputState TINYINT,Ref2_DoorState TINYINT,Ref2_ActiveState TINYINT" _
               & ",Ref3_RefAlarmState TINYINT,Ref3_LostPowerState TINYINT,Ref3_SoundOutputState TINYINT,Ref3_DoorState TINYINT,Ref3_ActiveState TINYINT" _
               & ",Ref4_RefAlarmState TINYINT,Ref4_LostPowerState TINYINT,Ref4_SoundOutputState TINYINT,Ref4_DoorState TINYINT,Ref4_ActiveState TINYINT,Ref5_DoorState TINYINT,Ref6_DoorState TINYINT,Ref7_DoorState TINYINT,Ref8_DoorState TINYINT" _
               & ", Primary Key(id))", pid_str, item.NetId)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史数据表的时间索引
            strSql = String.Format("CREATE INDEX index_hDate_{0}_{1} On tbccHDData_{2}_{3}(hDate)", pid_str, item.NetId, pid_str, item.NetId)
            tic.Add(strSql, Nothing)
        ElseIf item.DevAppType = 18 OrElse item.DevAppType = 16 Then

            '创建当前工程某网络的历史数据表
            strSql = String.Format("Create TABLE tbccHDData_{0}_{1}(id bigint not null auto_increment,hDate datetime,Uploadtime datetime,AI1 float(5,2),AI2 float(5,2),AI3 float(5,2)" _
               & ",AI4 float(5,2),AI5 float(5,2),AI6 float(5,2),AI7 float(5,2),AI8 float(5,2),AI9 float(5,2),AI10 float(5,2),AI11 float(5,2),AI12 float(5,2),AI13 float(5,2),AI14 float(5,2),AI15 float(5,2),AI16 float(5,2)" _
               & ",AI17 float(5,2),AI18 float(5,2),AI19 float(5,2),AI20 float(5,2),AI21 float(5,2),AI22 float(5,2),AI23 float(5,2),AI24 float(5,2),AI25 float(5,2),AI26 float(5,2),AI27 float(5,2)" _
               & ",AI28 float(5,2),AI29 float(5,2),AI30 float(5,2),AI31 float(5,2),AI32 float(5,2)" _
               & ",Ref1_LostPowerState TINYINT,Ref1_SoundOutputState TINYINT,Ref1_RefAlarmState TINYINT,Ref1_ActiveState TINYINT,Ref2_RefAlarmState TINYINT,Ref2_ActiveState TINYINT" _
               & ",Ref3_RefAlarmState TINYINT,Ref3_ActiveState TINYINT,Ref4_RefAlarmState TINYINT,Ref4_ActiveState TINYINT,Ref5_RefAlarmState TINYINT,Ref5_ActiveState TINYINT,Ref6_RefAlarmState TINYINT,Ref6_ActiveState TINYINT" _
               & ",Ref7_RefAlarmState TINYINT,Ref7_ActiveState TINYINT,Ref8_RefAlarmState TINYINT,Ref8_ActiveState TINYINT,Ref9_RefAlarmState TINYINT,Ref9_ActiveState TINYINT,Ref10_RefAlarmState TINYINT,Ref10_ActiveState TINYINT" _
               & ",Ref11_RefAlarmState TINYINT,Ref11_ActiveState TINYINT,Ref12_RefAlarmState TINYINT,Ref12_ActiveState TINYINT,Ref13_RefAlarmState TINYINT,Ref13_ActiveState TINYINT,Ref14_RefAlarmState TINYINT,Ref14_ActiveState TINYINT" _
               & ",Ref15_RefAlarmState TINYINT,Ref15_ActiveState TINYINT,Ref16_RefAlarmState TINYINT,Ref16_ActiveState TINYINT, Primary Key(id))", pid_str, item.NetId)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史数据表的时间索引
            strSql = String.Format("CREATE INDEX index_hDate_{0}_{1} On tbccHDData_{2}_{3}(hDate)", pid_str, item.NetId, pid_str, item.NetId)
            tic.Add(strSql, Nothing)

        End If



        If netcount = 0 Then '第一次创建网络设备
            '创建当前工程某网络的历史数据索引表
            strSql = String.Format("Create TABLE tbccHistoryData_{0}(netID TINYINT,iYear integer,iMonth integer,iDay integer," _
            & "iHour integer,iMinute integer,iSecond integer,UploadTime datetime)", pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史数据索引表的时间索引
            strSql = String.Format("CREATE INDEX index_net_time_{0} On tbccHistoryData_{1}(netID,iYear,iMonth,iDay,iHour,iMinute,iSecond)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            'strSql = String.Format("Create TABLE tbccHDAlarmData_{0}(id integer ,netID TINYINT,pageIndex integer,RowIndex TINYINT" _
            '& ",pageStartTime datetime,startTime datetime,A1 TINYINT,A2 TINYINT,A3 TINYINT,A4 TINYINT,A5 TINYINT,A6 TINYINT,A7 TINYINT,A8 TINYINT" _
            '& ",A9 TINYINT,A10 TINYINT,A11 TINYINT,A12 TINYINT,A13 TINYINT,A14 TINYINT,A15 TINYINT,A16 TINYINT,A17 TINYINT,A18 TINYINT,A19 TINYINT,A20 TINYINT" _
            '& ",A21 TINYINT,A22 TINYINT,A23 TINYINT,A24 TINYINT,AI1 float(5,2),AI2 float(5,2),AI3 float(5,2),AI4 float(5,2),AI5 float(5,2),AI6 float(5,2),AI7 float(5,2),AI8 float(5,2),AI9 float(5,2),AI10 float(5,2),AI11 float(5,2),AI12 float(5,2)" _
            '& ",A25 TINYINT,A26 TINYINT,A27 TINYINT,A28 TINYINT,A29 TINYINT,A30 TINYINT,A31 TINYINT,A32 TINYINT,A33 TINYINT,A34 TINYINT,A35 TINYINT,A36 TINYINT,A37 TINYINT,A38 TINYINT,A39 TINYINT,A40 TINYINT,A41 TINYINT,A42 TINYINT,A43 TINYINT,A44 TINYINT" _
            '& ",A45 TINYINT,A46 TINYINT,A47 TINYINT,A48 TINYINT,A49 TINYINT,A50 TINYINT,A51 TINYINT,A52 TINYINT,A53 TINYINT,A54 TINYINT,A55 TINYINT,A56 TINYINT,A57 TINYINT,A58 TINYINT,A59 TINYINT,A60 TINYINT,A61 TINYINT,A62 TINYINT,A63 TINYINT,A64 TINYINT" _
            '& ",AI13 float(5,2),AI14 float(5,2),AI15 float(5,2),AI16 float(5,2),AI17 float(5,2),AI18 float(5,2),AI19 float(5,2),AI20 float(5,2),AI21 float(5,2),AI22 float(5,2),AI23 float(5,2),AI24 float(5,2),AI25 float(5,2),AI26 float(5,2),AI27 float(5,2)" _
            '& ",AI28 float(5,2),AI29 float(5,2),AI30 float(5,2),AI31 float(5,2),AI32 float(5,2),Ref1_LostPowerAlarm TINYINT,Ref1_DoorAlarm TINYINT,Ref2_LostPowerAlarm TINYINT,Ref2_DoorAlarm TINYINT" _
            '& ",Ref3_LostPowerAlarm TINYINT,Ref3_DoorAlarm TINYINT,Ref4_LostPowerAlarm TINYINT,Ref4_DoorAlarm TINYINT,Ref5_DoorAlarm TINYINT,Ref6_DoorAlarm TINYINT,Ref7_DoorAlarm TINYINT,Ref8_DoorAlarm TINYINT,Ref1_JointActionOpenStatus TINYINT,Ref1_JointActionCloseStatus TINYINT,Ref1_JointAction_Output TINYINT,Ref1_DefrostStatus TINYINT" _
            '& ",Ref2_JointActionOpenStatus TINYINT,Ref2_JointActionCloseStatus TINYINT,Ref2_JointAction_Output TINYINT,Ref2_DefrostStatus TINYINT,Ref3_JointActionOpenStatus TINYINT,Ref3_JointActionCloseStatus TINYINT,Ref3_JointAction_Output TINYINT,Ref3_DefrostStatus TINYINT,Ref4_JointActionOpenStatus TINYINT,Ref4_JointActionCloseStatus TINYINT,Ref4_JointAction_Output TINYINT,Ref4_DefrostStatus TINYINT)", pid_str)

            strSql = String.Format("Create TABLE tbccHDAlarmData_{0}(id integer ,netID TINYINT,pageIndex integer,RowIndex TINYINT" _
            & ",pageStartTime datetime,startTime datetime,A1 TINYINT,A2 TINYINT,A3 TINYINT,A4 TINYINT,A5 TINYINT,A6 TINYINT,A7 TINYINT,A8 TINYINT" _
            & ",A9 TINYINT,A10 TINYINT,A11 TINYINT,A12 TINYINT,A13 TINYINT,A14 TINYINT,A15 TINYINT,A16 TINYINT,A17 TINYINT,A18 TINYINT,A19 TINYINT,A20 TINYINT" _
            & ",A21 TINYINT,A22 TINYINT,A23 TINYINT,A24 TINYINT,AI1 float(5,2),AI2 float(5,2),AI3 float(5,2),AI4 float(5,2),AI5 float(5,2),AI6 float(5,2),AI7 float(5,2),AI8 float(5,2),AI9 float(5,2),AI10 float(5,2),AI11 float(5,2),AI12 float(5,2)" _
            & ",A25 TINYINT,A26 TINYINT,A27 TINYINT,A28 TINYINT,A29 TINYINT,A30 TINYINT,A31 TINYINT,A32 TINYINT,A33 TINYINT,A34 TINYINT,A35 TINYINT,A36 TINYINT,A37 TINYINT,A38 TINYINT,A39 TINYINT,A40 TINYINT,A41 TINYINT,A42 TINYINT,A43 TINYINT,A44 TINYINT" _
            & ",A45 TINYINT,A46 TINYINT,A47 TINYINT,A48 TINYINT,A49 TINYINT,A50 TINYINT,A51 TINYINT,A52 TINYINT,A53 TINYINT,A54 TINYINT,A55 TINYINT,A56 TINYINT,A57 TINYINT,A58 TINYINT,A59 TINYINT,A60 TINYINT,A61 TINYINT,A62 TINYINT,A63 TINYINT,A64 TINYINT" _
            & ",AI13 float(5,2),AI14 float(5,2),AI15 float(5,2),AI16 float(5,2),AI17 float(5,2),AI18 float(5,2),AI19 float(5,2),AI20 float(5,2),AI21 float(5,2),AI22 float(5,2),AI23 float(5,2),AI24 float(5,2),AI25 float(5,2),AI26 float(5,2),AI27 float(5,2)" _
            & ",AI28 float(5,2),AI29 float(5,2),AI30 float(5,2),AI31 float(5,2),AI32 float(5,2),Ref_Network_Alarm TINYINT,Ref1_LostPowerAlarm TINYINT,Ref1_DoorAlarm TINYINT,Ref2_LostPowerAlarm TINYINT,Ref2_DoorAlarm TINYINT" _
            & ",Ref3_LostPowerAlarm TINYINT,Ref3_DoorAlarm TINYINT,Ref4_LostPowerAlarm TINYINT,Ref4_DoorAlarm TINYINT,Ref5_DoorAlarm TINYINT,Ref6_DoorAlarm TINYINT,Ref7_DoorAlarm TINYINT,Ref8_DoorAlarm TINYINT,Ref1_JointActionOpenStatus TINYINT,Ref1_JointActionCloseStatus TINYINT,Ref1_JointAction_Output TINYINT,Ref1_DefrostStatus TINYINT" _
            & ",Ref2_JointActionOpenStatus TINYINT,Ref2_JointActionCloseStatus TINYINT,Ref2_JointAction_Output TINYINT,Ref2_DefrostStatus TINYINT,Ref3_JointActionOpenStatus TINYINT,Ref3_JointActionCloseStatus TINYINT,Ref3_JointAction_Output TINYINT,Ref3_DefrostStatus TINYINT,Ref4_JointActionOpenStatus TINYINT,Ref4_JointActionCloseStatus TINYINT,Ref4_JointAction_Output TINYINT,Ref4_DefrostStatus TINYINT," _
            & "Generator_Alarm TINYINT,CompressorSetFailure1_Alarm TINYINT,CompressorSetFailure2_Alarm TINYINT,CompressorSetFailure3_Alarm TINYINT,CompressorSetFailure4_Alarm TINYINT,CompressorFailure1_Alarm TINYINT,CompressorFailure2_Alarm TINYINT,CompressorFailure3_Alarm TINYINT,CompressorFailure4_Alarm TINYINT,DefrostStatus1_Alarm TINYINT,DefrostStatus2_Alarm TINYINT,DefrostStatus3_Alarm TINYINT,DefrostStatus4_Alarm TINYINT)", pid_str)

            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史报警数据表的时间索引
            strSql = String.Format("CREATE INDEX index_HDAlarmData_{0} On tbccHDAlarmData_{1}(netID,startTime,pageIndex,RowIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史报警索引数据表
            strSql = String.Format("Create TABLE tbccAlarmData_{0}(netID TINYINT,pageIndex integer,StartTime datetime" _
            & ",EndTime datetime,UploadTime datetime,Finished TINYINT)", pid_str)
            tic.Add(strSql, Nothing)

            '创建当前工程某网络的历史报警索引数据表的时间索引
            strSql = String.Format("CREATE INDEX index_AlarmData_{0} On tbccAlarmData_{1}(netID,pageIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            '20100915增加DI历史数据表
            strSql = String.Format("Create TABLE tbccDiData_{0}(netID TINYINT,pageIndex integer,StartTime datetime" _
            & ",EndTime datetime,UploadTime datetime,Finished TINYINT)", pid_str)
            tic.Add(strSql, Nothing)

            strSql = String.Format("CREATE INDEX index_DiData_{0} On tbccDiData_{1}(netID,pageIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)

            strSql = String.Format("Create TABLE tbccHDDiData_{0}(id integer ,netID TINYINT,pageIndex integer,RowIndex TINYINT" _
          & ",pageStartTime datetime,startTime datetime,Ref1_DoorState TINYINT,Ref2_DoorState TINYINT,Ref3_DoorState TINYINT,Ref4_DoorState TINYINT,Ref5_DoorState TINYINT,Ref6_DoorState TINYINT,Ref7_DoorState TINYINT,Ref8_DoorState TINYINT,Ref1_JointAction TINYINT,Ref2_JointAction TINYINT,Ref3_JointAction TINYINT,Ref4_JointAction TINYINT," _
            & "Ref1_Compressor_Input TINYINT,Ref2_Compressor_Input TINYINT,Ref3_Compressor_Input TINYINT,Ref4_Compressor_Input TINYINT,Ref1_Cooling_Input TINYINT,Ref2_Cooling_Input TINYINT,Ref3_Cooling_Input TINYINT,Ref4_Cooling_Input TINYINT,Ref1_DefrostStatus TINYINT,Ref2_DefrostStatus TINYINT,Ref3_DefrostStatus TINYINT,Ref4_DefrostStatus TINYINT,Ref1_JointActionClose TINYINT,Ref2_JointActionClose TINYINT,Ref3_JointActionClose TINYINT,Ref4_JointActionClose TINYINT,Ref1_JointActionOpen TINYINT,Ref2_JointActionOpen TINYINT,Ref3_JointActionOpen TINYINT,Ref4_JointActionOpen TINYINT)", pid_str)
            tic.Add(strSql, Nothing)

            strSql = String.Format("CREATE INDEX index_HDDiData_{0} On tbccHDDiData_{1}(netID,startTime,pageIndex,RowIndex)", pid_str, pid_str)
            tic.Add(strSql, Nothing)
        End If


        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)

    End Function
    '为设备类型配置提供更新功能

    'Public Shared Function UpdateDevRefTypeList(ByVal item As DevTypeItem) As Boolean
    '    Dim strSql As String
    '    Dim index As Integer
    '    Dim tic As New TBCC.Utility.TranstrationItem

    '    strSql = String.Format("delete from TbccDevType where projectID='{0}' and Netid='{1}' -- " & index, item.ProjectID, item.NetId)
    '    tic.Add(strSql, Nothing)
    '    index += 1

    '    strSql = "Insert into TbccDevType(projectID,Netid,DevType,RefNum) Values(?p0,?p1,?p2,?p3) -- " & index

    '    Dim p1(3) As System.Data.Common.DbParameter

    '    p1(0) = New MySql.Data.MySqlClient.MySqlParameter()
    '    p1(0).ParameterName = "p0" : p1(0).Value = item.ProjectID

    '    p1(1) = New MySql.Data.MySqlClient.MySqlParameter()
    '    p1(1).ParameterName = "p1" : p1(1).Value = item.NetId

    '    p1(2) = New MySql.Data.MySqlClient.MySqlParameter()
    '    p1(2).ParameterName = "p2" : p1(2).Value = item.DevType

    '    p1(3) = New MySql.Data.MySqlClient.MySqlParameter()
    '    p1(3).ParameterName = "p3" : p1(3).Value = item.RefNum

    '    tic.Add(strSql, p1)
    '    index += 1


    '    strSql = String.Format("delete from TbccRefInfo where projectID='{0}' and Netid='{1}' -- " & index, item.ProjectID, item.NetId)
    '    tic.Add(strSql, Nothing)
    '    index += 1

    '    strSql = String.Format("delete from TbccAiInfo where projectID='{0}' and Netid='{1}' -- " & index, item.ProjectID, item.NetId)
    '    tic.Add(strSql, Nothing)
    '    index += 1

    '    strSql = String.Format("delete from TbccDiDoInfo where projectID='{0}' and Netid='{1}' -- " & index, item.ProjectID, item.NetId)
    '    tic.Add(strSql, Nothing)
    '    index += 1

    '    strSql = String.Format("delete from tbccImageControls where projectID='{0}' and Netid='{1}' -- " & index, item.ProjectID, item.NetId)
    '    tic.Add(strSql, Nothing)
    '    index += 1

    '    strSql = String.Format("delete from tbccIOInfo_Offline where projectID='{0}' and Netid='{1}' -- " & index, item.ProjectID, item.NetId)
    '    tic.Add(strSql, Nothing)
    '    index += 1

    '    strSql = String.Format("delete from tbccIOParameter_Offline where projectID='{0}' and Netid='{1}' -- " & index, item.ProjectID, item.NetId)
    '    tic.Add(strSql, Nothing)
    '    index += 1
    '    '**************************************************************
    '    '20090616 李吉鹏增加 为增加温湿度基准线及控制显示功能
    '    strSql = "Insert into TbccRefInfo(projectID,Netid,Refid,RealRefId,RefName,HDCurveTempUp,HDCurveTempDown,HDCurveHumiUp,HDCurveHumiDown,HDCurveTempLineUp,HDCurveTempLineDown,HDCurveHumiLineUp,HDCurveHumiLineDown,HDCurveTempLineUpShow,HDCurveTempLineDownShow,HDCurveHumiLineUpShow,HDCurveHumiLineDownShow,FloorType,FloorNo,RefType) Values(?p0,?p1,?p2,?p3,?p4,?p5,?p6,?p7,?p8,?p9,?p10,?p11,?p12,?p13,?p14,?p15,?p16,?p17,?p18,?p19) -- "


    '    For Each rti As RefTypeItem In item.RefTypeGroupList
    '        Dim p2(19) As System.Data.Common.DbParameter

    '        For i As Integer = 0 To p2.GetUpperBound(0)
    '            p2(i) = New MySql.Data.MySqlClient.MySqlParameter()
    '            p2(i).ParameterName = "p" + i.ToString
    '        Next

    '        p2(0).Value = item.ProjectID
    '        p2(1).Value = item.NetId
    '        p2(2).Value = rti.RefId
    '        p2(3).Value = rti.RealRefId
    '        p2(4).Value = rti.RefName
    '        p2(5).Value = rti.HDCurveTempUp
    '        p2(6).Value = rti.HDCurveTempDown
    '        p2(7).Value = rti.HDCurveHumiUp
    '        p2(8).Value = rti.HDCurveHumiDown

    '        p2(9).Value = rti.HDCurveTempLineUp
    '        p2(10).Value = rti.HDCurveTempLineDown
    '        p2(11).Value = rti.HDCurveHumiLineUp
    '        p2(12).Value = rti.HDCurveHumiLineDown

    '        p2(13).Value = IIf(rti.HDCurveTempLineUpShow, 1, 0)
    '        p2(14).Value = IIf(rti.HDCurveTempLineDownShow, 1, 0)
    '        p2(15).Value = IIf(rti.HDCurveHumiLineUpShow, 1, 0)
    '        p2(16).Value = IIf(rti.HDCurveHumiLineDownShow, 1, 0)

    '        p2(17).Value = rti.FloorType
    '        p2(18).Value = rti.FloorNo
    '        p2(19).Value = rti.RefType
    '        '****************************************************************************
    '        tic.Add(strSql & index, p2)
    '        index += 1
    '    Next

    '    Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)

    'End Function
    '为设备类型配置提供删除功能
    'netcount:剩余的设备的数量
    Public Shared Function DelDevRefTypeList(ByVal item As DevTypeItem, ByVal netcount As Integer) As Boolean
        Dim strSql As String
        Dim pid_str As String
        Dim tic As New TBCC.Utility.TranstrationItem

        pid_str = Trim(item.ProjectID).Replace("-", "_")

        '删除设备类型表的数据
        strSql = String.Format("delete from TbccDevType where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除冷库表的数据
        strSql = String.Format("delete from TbccRefInfo where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除AI端口表的数据
        strSql = String.Format("delete from TbccAiInfo where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除DI/DO端口表的数据
        strSql = String.Format("delete from TbccDiDoInfo where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        ''删除工程图表的数据
        'strSql = String.Format("Delete From tbccProjectImages Where projectID='{0}'", item.ProjectID)
        'tic.Add(strSql, Nothing)

        '删除工程图表中显示组件中的数据
        strSql = String.Format("Delete From tbccImageControls Where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除IO离线端口配置
        strSql = String.Format("Delete From tbccIOInfo_Offline Where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除IO离线参数配置
        strSql = String.Format("Delete From tbccIOParameter_Offline Where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除IO离线配置端口
        strSql = String.Format("Delete From tbccIOInfo_Offlinecold Where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除IO离线配置参数
        strSql = String.Format("Delete From tbccIOParameter_Offlinecold Where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除启停数据表
        strSql = String.Format("delete from tbcchddatastartendpage where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除手动上传数据表
        strSql = String.Format("delete from tbcchdmanualuploadrecord where projectID='{0}' and Netid={1}", item.ProjectID, item.NetId)
        tic.Add(strSql, Nothing)

        '删除当前工程某网络的历史数据表
        strSql = String.Format("Drop TABLE if exists tbccHDData_{0}_{1}", pid_str, item.NetId)
        tic.Add(strSql, Nothing)

        If netcount > 1 Then '如果当前已配置的设备数量大于1个
            '删除当前工程某网络的历史索引数据表
            strSql = String.Format("delete from tbccHistoryData_{0} where netID={1}", pid_str, item.NetId)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警数据表
            strSql = String.Format("delete from tbccHDAlarmData_{0} where netID={1}", pid_str, item.NetId)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警索引数据表
            strSql = String.Format("delete from tbccAlarmData_{0} where netID={1}", pid_str, item.NetId)
            tic.Add(strSql, Nothing)
        Else
            '删除当前工程某网络的历史索引数据表
            strSql = String.Format("drop TABLE if exists tbccHistoryData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警数据表
            strSql = String.Format("drop TABLE if exists tbccHDAlarmData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程某网络的历史报警索引数据表
            strSql = String.Format("drop TABLE if exists tbccAlarmData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '20100915DI 历史数据显示
            '删除当前工程DI历史数据索引表
            strSql = String.Format("Drop TABLE if exists tbccHDDiData_{0}", pid_str)
            tic.Add(strSql, Nothing)

            '删除当前工程DI历史数据表
            strSql = String.Format("Drop TABLE if exists tbccDiData_{0}", pid_str)
            tic.Add(strSql, Nothing)
        End If

        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)

    End Function

    ''' <summary>
    ''' 判断工程中是否包含指定的网络地址
    ''' </summary>
    ''' <param name="netID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function DevTypeExistNetid(ByVal pi As String, ByVal netID As Byte) As Boolean
        Dim strSql As String
        strSql = "Select count(*) from tbccDevType where projectID=?p0 and Netid =?p1"

        Dim p(1) As MySql.Data.MySqlClient.MySqlParameter
        p(0) = New MySql.Data.MySqlClient.MySqlParameter
        p(1) = New MySql.Data.MySqlClient.MySqlParameter

        p(0).ParameterName = "p0" : p(0).Value = pi
        p(1).ParameterName = "p1" : p(1).Value = netID

        Dim obj As Object
        obj = SqlHelper.ExecuteScalar(strSql, p)

        If obj = 0 Then
            Return False
        End If

        Return True
    End Function


    ''' <summary>
    ''' 获取当前工程中最大的netid
    ''' </summary>    
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function DevTypeMaxNetid(ByVal pi As String, ByVal devtype As Integer) As Integer
        Dim strSql As String

        If devtype = 1 OrElse devtype = 17 Then
            devtype = 17
        ElseIf devtype = 16 OrElse devtype = 18 Then
            devtype = 18

        End If
        strSql = "Select max(Netid) from tbccDevType where projectID=?p0 and devAppType=?p1"

        Dim p(1) As MySql.Data.MySqlClient.MySqlParameter
        p(0) = New MySql.Data.MySqlClient.MySqlParameter
        p(0).ParameterName = "p0" : p(0).Value = pi

        p(1) = New MySql.Data.MySqlClient.MySqlParameter
        p(1).ParameterName = "p1" : p(1).Value = devtype

        Dim obj As Object
        obj = SqlHelper.ExecuteScalar(strSql, p)

        If obj Is Nothing OrElse IsDBNull(obj) Then

            If devtype = 17 Then
                Return 0
            ElseIf devtype = 18 Then
                Return 99
            End If

        Else
            Return CInt(obj)
        End If


    End Function


    '根据冷库ID获取某工程和网络的冷库名称
    Public Shared Function GetRefName_FromRefid(ByVal pi As ProjectItem, ByVal netID As Byte, ByVal Refid As Integer) As String
        For Each dti As DevTypeItem In pi.DevTypeGroupList
            If dti.NetId = netID Then
                For Each rti As RefTypeItem In dti.RefTypeGroupList
                    If rti.RefId = Refid Then
                        Return rti.RefName
                    End If
                Next
            End If
        Next
        Return ""
    End Function


    '根据冷库端口编号获取某工程和网络的冷库名称
    Public Shared Function GetRefName_FromPortNo(ByVal pi As ProjectItem, ByVal netID As Byte, ByVal PortNo As Integer) As String
        For Each dti As DevTypeItem In pi.DevTypeGroupList
            If dti.NetId = netID Then
                For Each rti As RefTypeItem In dti.RefTypeGroupList
                    For Each apti As AiPortTypeItem In rti.AiPortTypeGroupList
                        If apti.PortNo = PortNo Then
                            Return rti.RefName
                        End If
                    Next
                Next
            End If
        Next
        Return ""
    End Function

    '根据冷库端口编号获取某工程和网络的该端口名称
    Public Shared Function GetPortName_FromPortNo(ByVal pi As ProjectItem, ByVal netID As Byte, ByVal PortNo As Integer) As String
        For Each dti As DevTypeItem In pi.DevTypeGroupList
            If dti.NetId = netID Then
                For Each rti As RefTypeItem In dti.RefTypeGroupList
                    For Each apti As AiPortTypeItem In rti.AiPortTypeGroupList
                        If apti.PortNo = PortNo Then
                            Return apti.PortName
                        End If
                    Next
                Next
            End If
        Next
        Return ""
    End Function

    '根据冷库编号确定当前DI/DO是否有效
    'm_type: 1: 缺项是否配置; 2: 库门是否配置;3:2#库门是否配置
    Public Shared Function GetDioStatus(ByVal pi As ProjectItem, ByVal netID As Byte, ByVal m_type As Integer) As Boolean
        For Each dti As DevTypeItem In pi.DevTypeGroupList
            If dti.NetId = netID Then
                For Each rti As RefTypeItem In dti.RefTypeGroupList

                    If m_type = 1 Then '缺项是否配置
                        Return IIf(rti.DiDoPortInfo.LostPowerPort > 0, True, False)
                    End If

                    If m_type = 2 Then '库门是否配置
                        Return IIf(rti.DiDoPortInfo.DoorStatusPort > 0, True, False)
                    End If

                    If m_type = 3 Then '2#库门是否配置
                        Return IIf(rti.DiDoPortInfo.DoorStatusPort2 > 0, True, False)
                    End If


                    If m_type = 4 Then '仓库联动报警
                        Return IIf(rti.DiDoPortInfo.JointActionOpen_Output_Nu > 0, True, False)
                    End If

                    If m_type = 5 Then '仓库联动报警
                        Return IIf(rti.DiDoPortInfo.JointActionClose_Output_Nu > 0, True, False)
                    End If
                    If m_type = 6 Then '发电机故障报警
                        Return IIf(rti.DiDoPortInfo.GeneratorPreAlarm_Nu > 0, True, False)
                    End If
                    If m_type = 7 Then '压缩机故障报警
                        Return IIf(rti.DiDoPortInfo.CompressorFailure_Input_Nu > 0, True, False)
                    End If
                    If m_type = 8 Then '机组故障报警
                        Return IIf(rti.DiDoPortInfo.CompressorSetFailure_Input_Nu > 0, True, False)
                    End If
                    If m_type = 9 Then '除霜故障报警
                        Return IIf(rti.DiDoPortInfo.DefrostStatus_Input_Nu > 0, True, False)
                    End If

                Next
            End If
        Next

        Return False

    End Function

#End Region


End Class
